NAME
TPath::Attributes::Extended - a collection of attributes beyond the standard set
VERSION
version 1.007
SYNOPSIS
# mix in the extended attribute set
{
package BetterForester;
use Moose;
extends 'MyForester';
with 'TPath::Attributes::Extended';
}
my $f = BetterForester->new;
my $path = $f->path('//*[@s:concat("", *) = "blarmy"]'); # new attribute!
my $tree = next_tree();
my @blarmies = $path->select($tree);
DESCRIPTION
TPath::Attributes::Extended
provides a collection of useful functions generally corresponding to functions available in XPath. The attribute names of these functions are preceded with a prefix indicating their domain of application.
METHODS
@m:abs(-1)
Absolute value of numeric argument.
@m:ceil(1.5)
Returns smallest whole number greater than or equal to the numeric argument.
@m:floor(1.5)
Returns largest whole number less than or equal to the numeric argument.
@m:int(1.5)
Returns integer portion of the numeric argument.
@m:round(1.5)
Rounds numeric argument to the nearest whole number relying on sprintf '%.0f'
for the rounding.
@m:max(1,2,3,4,5)
Takes an arbitrary number of arguments and returns the maximum, treating them as numbers.
@m:min(1,2,3,4,5)
Takes an arbitrary number of arguments and returns the minimum, treating them as numbers.
@m:sum(1,2,3,4,5)
Takes an arbitrary number of arguments and returns the sum, treating them as numbers.
@m:prod(1,2,3,4,5)
Takes an arbitrary number of arguments and returns the product, treating them as numbers. An empty list returns 0.
@s:matches('str','re')
Returns whether the given string matches the given regex. That is, if the regex is $re
, the regex tested against is ^$re$
. Note that this is redundant: one can also use the =~
operator for this purpose.
//foo[@bar =~ '^baz$']
@s:looking-at('str','re')
Returns whether a prefix of the given string matches the given regex. That is, if the regex given is $re
, the regex tested against is ^$re
. Note that this is redundant: one can also use the =~
operator for this purpose.
//foo[@bar =~ '^baz']
@s:find('str','re')
Returns whether a prefix of the given string matches the given regex anywhere. Note that this is redundant: one can also use the =~
operator for this purpose.
//foo[@bar =~ 'baz']
@s:starts-with('str','prefix')
Whether the string has the given prefix. Note that this is redundant: one can also use the |=
operator for this purpose.
//foo[@bar |= 'baz']
@s:ends-with('str','suffix')
Whether the string has the given suffix. Note that this is redundant: one can also use the =|
operator for this purpose.
//foo[@bar =| 'baz']
@s:contains('str','infix')
Whether the string contains the given substring. Note that this is redundant: one can also use the =|=
operator for this purpose.
//foo[@bar =|= 'baz']
@s:index('str','substr')
The index of the substring within the string.
@s:concat('foo','bar','baz','quux','plugh')
Takes an arbitrary number of arguments and returns their concatenation as a string.
@s:replace-first('str','rx','rep')
Takes a string, a pattern, and a replacement and returns the string, replacing the first pattern match with the replacement.
@s:replace-all('str','rx','rep')
Takes a string, a pattern, and a replacement and returns the string, replacing every pattern match with the replacement.
@s:replace('str','substr','rep')
Takes a string, a substring, and a replacement and returns the string, replacing every literal occurrence of the substring with the replacement string.
@s:cmp('s1','s2')
Takes two strings and returns the comparison of the two using cmp
.
@s:substr('s',1,2)
Expects a string and one or two indices. If one index is received, returns
substr $s, $i1
otherwise, returns
substr $s, $i1, $i2 - $i1
That is, the second index is understood to be an end index rather than the length of the substring. This is done to make the Perl version of @s:substr
semantically identical to the Java version.
@s:len('str')
The length of the string parameter.
@s:uc('str')
The string parameter in uppercase.
@s:lc('str')
The string parameter in lowercase.
@s:ucfirst('str')
The function ucfirst
applied to the string parameter.
@s:trim('str')
Removes marginal whitespace from string parameter.
@s:nspace('str')
Normalizes all whitespace in string parameter, stripping off marginal space and converting all interior space sequences into single whitespaces.
@s:join('sep',s1','s2','s3')
Joins together a list of arguments with the given separator. The arguments and separator will all be stringified. If the separator is undefined, its stringification will be null
to keep it semantically equivalent to the Java version of @s:join
.
@u:millis
The system time in milliseconds.
@u:def(@arg)
Whether the argument is defined.
AUTHOR
David F. Houghton <dfhoughton@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by David F. Houghton.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.