Template::Plugin::ScalarUtil - Scalar::Util plugin for Template-Toolkit
version 1.121160
[% USE ScalarUtil %] # blessed [% ScalarUtil.blessed(EXPR) ? 'blessed' : 'not blessed' %] # dualvar [% SET dv = ScalarUtil.dualvar( 5, "Hello" ) %] [% SET num = dv + 7 %] [% SET string = dv _ " world!" %] [% num == string.length ? "correct" : "ups" %] # isvstring [% ScalarUtil.isvstring(vstring) ? 'is vstring' : 'is not vstring' %] # looks_like_number [% ScalarUtil.looks_like_number('Infinity') ? 'number' : 'not number' %] # openhandle [% ScalarUtil.openhandle(FH) ? "opened" : "not opened" %] # refaddr [% ScalarUtil.refaddr(EXPR) %] # reftype [% ScalarUtil.reftype(EXPR) %] # tainted [% ScalarUtil.tainted(EXPR) %]
Use Scalar::Util functions in your templates.
[% IF ScalarUtil.blessed(EXPR); EXPR.method(args); END; %]
Returns the name of the package if EXPR is a blessed reference.
EXPR
[% SET dv = ScalarUtil.dualvar( num, string ) %]
Returns a scalar that has the value num in a numeric context and the value string in a string context.
num
string
[% USE vstring = format('%vd'); USE string = format('%s'); IF ScalarUtil.isvstring(EXPR); vstring(EXPR); ELSE; string(EXPR); END; %]
Returns true if EXPR was coded as vstring;
[% IF ScalarUtil.looks_like_number(EXPR) %] [% EXPR %] looks like number [% END %]
Returns true if perl thinks EXPR is a number.
[% IF ScalarUtil.openhandle(FH) %] FH is an opened filehandle [% END %]
Returns FH if it is opened filehandle, undef otherwise.
FH
undef
[% ScalarUtil.refaddr(EXPR) %]
Returns internal memory address of the EXPR if it is a reference, undef otherwise.
[% SWITCH ScalarUtil.reftype(EXPR) %] [% CASE 'ARRAY' %] [% EXPR.size %] [% CASE 'HASH' %] [% EXPR.list.size %] [% END %]
Returns the type of the EXPR if it is a reference, undef otherwise.
[% IF ScalarUtil.tainted(EXPR) %] EXPR is tainted [% END %]
Returns true if EXPR is tainted.
Please note that following methods were NOT implemented due to the nature of TT's stash.
isweak
readonly
set_prototype
weaken
Please see those modules/websites for more information related to this module.
Scalar::Util
Alex J. G. Burzyński <ajgb@cpan.org>
This software is copyright (c) 2012 by Alex J. G. Burzyński <ajgb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Template::Plugin::ScalarUtil, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Plugin::ScalarUtil
CPAN shell
perl -MCPAN -e shell install Template::Plugin::ScalarUtil
For more information on module installation, please visit the detailed CPAN module installation guide.