NAME Petal::Utils - Useful template modifiers for Petal. SYNOPSIS # install the default set of Petal modifiers: use Petal::Utils; # you can also install modifiers manually: Petal::Utils->install( 'some_modifier', ':some_set' ); # see below for modifiers available & template syntax DESCRIPTION The Petal::Utils package contains commonly used Petal modifiers (or plugins), and bundles them with an easy-to-use installation interface. By default, a set of modifiers are installed into Petal when you use this module. You can change which modifiers are installed by naming them after the use statement: # use the default set: use Petal::Utils qw( :default ); # use the date set of modifiers: use Petal::Utils qw( :date ); # use only named modifiers, plus the debug set: use Petal::Utils qw( UpperCase Date :debug ); # don't install any modifiers use Petal::Utils qw(); You'll find a list of plugin sets throughout this document. You can also get a complete list by looking at the variable: %Petal::Utils::PLUGIN_SET; For details on how the plugins are installed, see the "Advanced Petal" section of the Petal documentation. MODIFIERS Each modifier is listed under the set it belongs to. :text lowercase:, lc: $string Make the entire string lowercase.
lower
uppercase:, uc: $string Make the entire string uppercase.upper
uc_first: $string Make the first letter of the string uppercase.uc_first
substr: $string [offset] [length] [ellipsis] Extract a substring from a string. Optionally add an ellipsis (...) to the end. See also, perldoc -f substr. string # does nothing string # cuts the first two chars string # extracts chars 2-7 string with ellipsis # same as above and adds an ellipsis printf: format list The printf modifier acts exactly like Perl's sprintf function to print formatted strings.Astro
$2.50
:date date: $date Convert a time() integer to a date string using Date::Format. Jan 1 1970 01:00:01 us_date: $date Convert an international date stamp (e.g., yyyymmdd, yyyy-mm-dd, yyyy/mm/dd) to US format (mm/dd/yyyy).2003-09-05
:logic if: $expr1 then: $expr2 else: $expr3 Do an if/then/else test and return the value of the expression executed. Truthfulness of $expr1 is according to Perl (e.g., non-zero, non-empty string).Some text here...
or: $expr1 $expr2 Do a logical or. Truthfulness is according to Perl (e.g., non-zero, non-empty string).first or second = or
and: $expr1 $expr2 Do a logical and. Truthfulness is according to Perl (e.g., non-zero, non-empty string). first and second = and equal:, eq: $expr1 $expr2 Test for equality. Numbers are compared with "==", strings with "eq". Truthfulness is according to Perl (e.g., non-zero, non-empty string). first eq second = equal like: $expr $regex Test for equality to a regular expression (see perlre). name like regex = like decode, decode: expression search result [search result]... [default] The decode function has the functionality of an IF-THEN-ELSE statement. A case-sensitive regex comparison is performed. All text strings must be enclosed in single quotes. 'expression' is the value to compare. 'search' is the value that is compared against expression. 'result' is the value returned, if expression is equal to search. 'default. is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).100
# if $str = dog, returns SatchelAstro
# if $str = cat, returns Buckey, else Satchel :list sort: $list Sort the values in a list before returning it.