subroutines
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 245
B::Utils 0.30
B::Utils is a helper functions for op tree manipulation. more>>
B::Utils is a helper functions for op tree manipulation.
SYNOPSIS
use B::Utils;
These functions make it easier to manipulate the op tree.
FUNCTIONS
all_starts
all_roots
Returns a hash of all of the starting ops or root ops of optrees, keyed to subroutine name; the optree for main program is simply keyed to __MAIN__.
Note: Certain "dangerous" stashes are not scanned for subroutines: the list of such stashes can be found in @B::Utils::bad_stashes. Feel free to examine and/or modify this to suit your needs. The intention is that a simple program which uses no modules other than B and B::Utils would show no addition symbols.
This does not return the details of ops in anonymous subroutines compiled at compile time. For instance, given
$a = sub { ... };
the subroutine will not appear in the hash. This is just as well, since theyre anonymous... If you want to get at them, use...
anon_subs()
This returns an array of hash references. Each element has the keys "start" and "root". These are the starting and root ops of all of the anonymous subroutines in the program.
$op->oldname
Returns the name of the op, even if it is currently optimized to null. This helps you understand the stucture of the op tree.
$op->kids
Returns an array of all this ops non-null children, in order.
$op->first
$op->last
$op->other
Normally if you call first, last or other on anything which is not an UNOP, BINOP or LOGOP respectivly it will die. This leads to lots of code like:
$op->first if $op->can(first);
B::Utils provides every op with first, last and other methods which will simply return nothing if it isnt relevent.
$op->parent
Returns the parent node in the op tree, if possible. Currently "possible" means "if the tree has already been optimized"; that is, if were during a CHECK block. (and hence, if we have valid next pointers.)
In the future, it may be possible to search for the parent before we have the next pointers in place, but itll take me a while to figure out how to do that.
$op->previous
Like $op->next, but not quite.
walkoptree_simple($op, &callback, [$data])
The B module provides various functions to walk the op tree, but theyre all rather difficult to use, requiring you to inject methods into the B::OP class. This is a very simple op tree walker with more expected semantics.
The &callback is called at each op with the op itself passed in as the first argument and any additional $data as the second.
All the walk functions set $B::Utils::file and $B::Utils::line to the appropriate values of file and line number in the program being examined. Since only COPs contain this information it may be unavailable in the first few callback calls.
walkoptree_filtered($op, &filter, &callback, [$data])
This is much the same as walkoptree_simple, but will only call the callback if the filter returns true. The filter is passed the op in question as a parameter; the opgrep function is fantastic for building your own filters.
walkallops_simple(&callback, [$data])
This combines walkoptree_simple with all_roots and anon_subs to examine every op in the program. $B::Utils::sub is set to the subroutine name if youre in a subroutine, __MAIN__ if youre in the main program and __ANON__ if youre in an anonymous subroutine.
walkallops_filtered(&filter, &callback, [$data])
Same as above, but filtered.
<<lessSYNOPSIS
use B::Utils;
These functions make it easier to manipulate the op tree.
FUNCTIONS
all_starts
all_roots
Returns a hash of all of the starting ops or root ops of optrees, keyed to subroutine name; the optree for main program is simply keyed to __MAIN__.
Note: Certain "dangerous" stashes are not scanned for subroutines: the list of such stashes can be found in @B::Utils::bad_stashes. Feel free to examine and/or modify this to suit your needs. The intention is that a simple program which uses no modules other than B and B::Utils would show no addition symbols.
This does not return the details of ops in anonymous subroutines compiled at compile time. For instance, given
$a = sub { ... };
the subroutine will not appear in the hash. This is just as well, since theyre anonymous... If you want to get at them, use...
anon_subs()
This returns an array of hash references. Each element has the keys "start" and "root". These are the starting and root ops of all of the anonymous subroutines in the program.
$op->oldname
Returns the name of the op, even if it is currently optimized to null. This helps you understand the stucture of the op tree.
$op->kids
Returns an array of all this ops non-null children, in order.
$op->first
$op->last
$op->other
Normally if you call first, last or other on anything which is not an UNOP, BINOP or LOGOP respectivly it will die. This leads to lots of code like:
$op->first if $op->can(first);
B::Utils provides every op with first, last and other methods which will simply return nothing if it isnt relevent.
$op->parent
Returns the parent node in the op tree, if possible. Currently "possible" means "if the tree has already been optimized"; that is, if were during a CHECK block. (and hence, if we have valid next pointers.)
In the future, it may be possible to search for the parent before we have the next pointers in place, but itll take me a while to figure out how to do that.
$op->previous
Like $op->next, but not quite.
walkoptree_simple($op, &callback, [$data])
The B module provides various functions to walk the op tree, but theyre all rather difficult to use, requiring you to inject methods into the B::OP class. This is a very simple op tree walker with more expected semantics.
The &callback is called at each op with the op itself passed in as the first argument and any additional $data as the second.
All the walk functions set $B::Utils::file and $B::Utils::line to the appropriate values of file and line number in the program being examined. Since only COPs contain this information it may be unavailable in the first few callback calls.
walkoptree_filtered($op, &filter, &callback, [$data])
This is much the same as walkoptree_simple, but will only call the callback if the filter returns true. The filter is passed the op in question as a parameter; the opgrep function is fantastic for building your own filters.
walkallops_simple(&callback, [$data])
This combines walkoptree_simple with all_roots and anon_subs to examine every op in the program. $B::Utils::sub is set to the subroutine name if youre in a subroutine, __MAIN__ if youre in the main program and __ANON__ if youre in an anonymous subroutine.
walkallops_filtered(&filter, &callback, [$data])
Same as above, but filtered.
Download (0.043MB)
Added: 2006-07-04 License: Perl Artistic License Price:
1207 downloads
Sub::Regex 0.02
Sub::Regex is a Perl module to create synonymous subroutines. more>>
Sub::Regex is a Perl module to create synonymous subroutines.
SYNOPSIS
use Sub::Regex;
sub /look(s|ing)?_for/ ($){
foobar blah blah
}
look_for(Amanda);
looks_for(Amanda);
looking_for(Amanda);
lOoKiNg_fOr(Amanda);
Sub::Regex is a small tool for users to create a subroutine with multiple names. The only thing to be done is replace the normal name of a subroutine with a regular expression. However, regexp modifiers are not allowed, and matching is all considered case-insensitive.
<<lessSYNOPSIS
use Sub::Regex;
sub /look(s|ing)?_for/ ($){
foobar blah blah
}
look_for(Amanda);
looks_for(Amanda);
looking_for(Amanda);
lOoKiNg_fOr(Amanda);
Sub::Regex is a small tool for users to create a subroutine with multiple names. The only thing to be done is replace the normal name of a subroutine with a regular expression. However, regexp modifiers are not allowed, and matching is all considered case-insensitive.
Download (0.002MB)
Added: 2007-05-03 License: Perl Artistic License Price:
905 downloads
Strings edit 1.9
Strings edit is a library that provides I/O facilities for integer, floating-point, Roman numbers, and strings. more>>
Strings edit is a library that provides I/O facilities for integer, floating-point, Roman numbers, and strings. Both input and output subroutines support string pointers for consequent stream processing. The output can be aligned in a fixed size field with padding.
Numeric input can be checked against expected values range to be either saturated or to raise an exception. For floating-point output either relative or absolute output precision can be specified. UTF-8 encoded strings are supported.
Enhancements:
- GPS project files were added for GNAT users.
- A bug was fixed in Strings_Edit.Generic_Scale in which the caclculated precision was of the minor scale tick rather than of the major tick.
<<lessNumeric input can be checked against expected values range to be either saturated or to raise an exception. For floating-point output either relative or absolute output precision can be specified. UTF-8 encoded strings are supported.
Enhancements:
- GPS project files were added for GNAT users.
- A bug was fixed in Strings_Edit.Generic_Scale in which the caclculated precision was of the minor scale tick rather than of the major tick.
Download (0.053MB)
Added: 2007-05-20 License: GMGPL (GNAT Modified GPL) Price:
908 downloads
Scalar::Util 1.19
Scalar::Util is a selection of general-utility scalar subroutines. more>>
Scalar::Util is a selection of general-utility scalar subroutines.
SYNOPSIS
use Scalar::Util qw(blessed dualvar isweak readonly refaddr reftype tainted
weaken isvstring looks_like_number set_prototype);
Scalar::Util contains a selection of subroutines that people have expressed would be nice to have in the perl core, but the usage would not really be high enough to warrant the use of a keyword, and the size so small such that being individual extensions would be wasteful.
By default Scalar::Util does not export any subroutines. The subroutines defined are
blessed EXPR
If EXPR evaluates to a blessed reference the name of the package that it is blessed into is returned. Otherwise undef is returned.
$scalar = "foo";
$class = blessed $scalar; # undef
$ref = [];
$class = blessed $ref; # undef
$obj = bless [], "Foo";
$class = blessed $obj; # "Foo"
dualvar NUM, STRING
Returns a scalar that has the value NUM in a numeric context and the value STRING in a string context.
$foo = dualvar 10, "Hello";
$num = $foo + 2; # 12
$str = $foo . " world"; # Hello world
isvstring EXPR
If EXPR is a scalar which was coded as a vstring the result is true.
$vs = v49.46.48;
$fmt = isvstring($vs) ? "%vd" : "%s"; #true
printf($fmt,$vs);
isweak EXPR
If EXPR is a scalar which is a weak reference the result is true.
$ref = $foo;
$weak = isweak($ref); # false
weaken($ref);
$weak = isweak($ref); # true
NOTE: Copying a weak reference creates a normal, strong, reference.
$copy = $ref;
$weak = isweak($ref); # false
looks_like_number EXPR
Returns true if perl thinks EXPR is a number. See "looks_like_number" in perlapi.
openhandle FH
Returns FH if FH may be used as a filehandle and is open, or FH is a tied handle. Otherwise undef is returned.
$fh = openhandle(*STDIN); # *STDIN
$fh = openhandle(*STDIN); # *STDIN
$fh = openhandle(*NOTOPEN); # undef
$fh = openhandle("scalar"); # undef
readonly SCALAR
Returns true if SCALAR is readonly.
sub foo { readonly($_[0]) }
$readonly = foo($bar); # false
$readonly = foo(0); # true
refaddr EXPR
If EXPR evaluates to a reference the internal memory address of the referenced value is returned. Otherwise undef is returned.
$addr = refaddr "string"; # undef
$addr = refaddr $var; # eg 12345678
$addr = refaddr []; # eg 23456784
$obj = bless {}, "Foo";
$addr = refaddr $obj; # eg 88123488
reftype EXPR
If EXPR evaluates to a reference the type of the variable referenced is returned. Otherwise undef is returned.
$type = reftype "string"; # undef
$type = reftype $var; # SCALAR
$type = reftype []; # ARRAY
$obj = bless {}, "Foo";
$type = reftype $obj; # HASH
set_prototype CODEREF, PROTOTYPE
Sets the prototype of the given function, or deletes it if PROTOTYPE is undef. Returns the CODEREF.
set_prototype &foo, $$;
tainted EXPR
Return true if the result of EXPR is tainted
$taint = tainted("constant"); # false
$taint = tainted($ENV{PWD}); # true if running under -T
weaken REF
REF will be turned into a weak reference. This means that it will not hold a reference count on the object it references. Also when the reference count on that object reaches zero, REF will be set to undef.
This is useful for keeping copies of references , but you dont want to prevent the object being DESTROY-ed at its usual time.
{
my $var;
$ref = $var;
weaken($ref); # Make $ref a weak reference
}
# $ref is now undef
Note that if you take a copy of a scalar with a weakened reference, the copy will be a strong reference.
my $var;
my $foo = $var;
weaken($foo); # Make $foo a weak reference
my $bar = $foo; # $bar is now a strong reference
This may be less obvious in other situations, such as grep(), for instance when grepping through a list of weakened references to objects that may have been destroyed already:
@object = grep { defined } @object;
This will indeed remove all references to destroyed objects, but the remaining references to objects will be strong, causing the remaining objects to never be destroyed because there is now always a strong reference to them in the @object array.
<<lessSYNOPSIS
use Scalar::Util qw(blessed dualvar isweak readonly refaddr reftype tainted
weaken isvstring looks_like_number set_prototype);
Scalar::Util contains a selection of subroutines that people have expressed would be nice to have in the perl core, but the usage would not really be high enough to warrant the use of a keyword, and the size so small such that being individual extensions would be wasteful.
By default Scalar::Util does not export any subroutines. The subroutines defined are
blessed EXPR
If EXPR evaluates to a blessed reference the name of the package that it is blessed into is returned. Otherwise undef is returned.
$scalar = "foo";
$class = blessed $scalar; # undef
$ref = [];
$class = blessed $ref; # undef
$obj = bless [], "Foo";
$class = blessed $obj; # "Foo"
dualvar NUM, STRING
Returns a scalar that has the value NUM in a numeric context and the value STRING in a string context.
$foo = dualvar 10, "Hello";
$num = $foo + 2; # 12
$str = $foo . " world"; # Hello world
isvstring EXPR
If EXPR is a scalar which was coded as a vstring the result is true.
$vs = v49.46.48;
$fmt = isvstring($vs) ? "%vd" : "%s"; #true
printf($fmt,$vs);
isweak EXPR
If EXPR is a scalar which is a weak reference the result is true.
$ref = $foo;
$weak = isweak($ref); # false
weaken($ref);
$weak = isweak($ref); # true
NOTE: Copying a weak reference creates a normal, strong, reference.
$copy = $ref;
$weak = isweak($ref); # false
looks_like_number EXPR
Returns true if perl thinks EXPR is a number. See "looks_like_number" in perlapi.
openhandle FH
Returns FH if FH may be used as a filehandle and is open, or FH is a tied handle. Otherwise undef is returned.
$fh = openhandle(*STDIN); # *STDIN
$fh = openhandle(*STDIN); # *STDIN
$fh = openhandle(*NOTOPEN); # undef
$fh = openhandle("scalar"); # undef
readonly SCALAR
Returns true if SCALAR is readonly.
sub foo { readonly($_[0]) }
$readonly = foo($bar); # false
$readonly = foo(0); # true
refaddr EXPR
If EXPR evaluates to a reference the internal memory address of the referenced value is returned. Otherwise undef is returned.
$addr = refaddr "string"; # undef
$addr = refaddr $var; # eg 12345678
$addr = refaddr []; # eg 23456784
$obj = bless {}, "Foo";
$addr = refaddr $obj; # eg 88123488
reftype EXPR
If EXPR evaluates to a reference the type of the variable referenced is returned. Otherwise undef is returned.
$type = reftype "string"; # undef
$type = reftype $var; # SCALAR
$type = reftype []; # ARRAY
$obj = bless {}, "Foo";
$type = reftype $obj; # HASH
set_prototype CODEREF, PROTOTYPE
Sets the prototype of the given function, or deletes it if PROTOTYPE is undef. Returns the CODEREF.
set_prototype &foo, $$;
tainted EXPR
Return true if the result of EXPR is tainted
$taint = tainted("constant"); # false
$taint = tainted($ENV{PWD}); # true if running under -T
weaken REF
REF will be turned into a weak reference. This means that it will not hold a reference count on the object it references. Also when the reference count on that object reaches zero, REF will be set to undef.
This is useful for keeping copies of references , but you dont want to prevent the object being DESTROY-ed at its usual time.
{
my $var;
$ref = $var;
weaken($ref); # Make $ref a weak reference
}
# $ref is now undef
Note that if you take a copy of a scalar with a weakened reference, the copy will be a strong reference.
my $var;
my $foo = $var;
weaken($foo); # Make $foo a weak reference
my $bar = $foo; # $bar is now a strong reference
This may be less obvious in other situations, such as grep(), for instance when grepping through a list of weakened references to objects that may have been destroyed already:
@object = grep { defined } @object;
This will indeed remove all references to destroyed objects, but the remaining references to objects will be strong, causing the remaining objects to never be destroyed because there is now always a strong reference to them in the @object array.
Download (0.042MB)
Added: 2007-05-21 License: Perl Artistic License Price:
888 downloads
Sub::Curry 0.8
Sub::Curry is a Perl module to create curried subroutines. more>>
Sub::Curry is a Perl module to create curried subroutines.
SYNOPSIS
use Sub::Curry;
use Sub::Curry qw/ :CONST curry /; # Import spice constants
# and the &curry function.
#my $f1 = Sub::Curry::->new(&foo, 1, 2); # Same as below.
my $f1 = curry(&foo, 1, 2);
my $f2 = $cb1->new(3, 4);
my $f3 = curry(&foo, 1, HOLE, 3);
my $f4 = $f3->new(2, 4);
$f1->(a); # foo(1, 2, a);
$f2->(a); # foo(1, 2, 3, 4, a);
$f3->(a); # foo(1, a, 3);
$f4->(a); # foo(1, 2, 3, 4, a);
$f4->call(a); # Same as $cb4->(a);
Sub::Curry is a module that provides the currying technique known from functional languages. This module, unlike many other modules that borrow techniques from functional languages, doesnt try to make Perl functional. Instead it tries to make currying Perlish.
This module aims to be a base for other modules that use/provide currying techniques.
This module supports a unique set of special spices (argument features). It doesnt just support holes, but also introduces antiholes, blackholes, whiteholes, and antispices. All these extra special spices effect how the spice is applied to the subroutine. They make functions such as &rcurry superfluous. See "Currying" and Sub::Curry::Cookbook.
An oft-missed feature is argument aliasing. This module preserves the aliasing.
Sub::Curry does explicit currying. For more automatic ways to use currying, look in the Sub::Curry::* namespace.
When version hits 1.00 the interface will be stable.
<<lessSYNOPSIS
use Sub::Curry;
use Sub::Curry qw/ :CONST curry /; # Import spice constants
# and the &curry function.
#my $f1 = Sub::Curry::->new(&foo, 1, 2); # Same as below.
my $f1 = curry(&foo, 1, 2);
my $f2 = $cb1->new(3, 4);
my $f3 = curry(&foo, 1, HOLE, 3);
my $f4 = $f3->new(2, 4);
$f1->(a); # foo(1, 2, a);
$f2->(a); # foo(1, 2, 3, 4, a);
$f3->(a); # foo(1, a, 3);
$f4->(a); # foo(1, 2, 3, 4, a);
$f4->call(a); # Same as $cb4->(a);
Sub::Curry is a module that provides the currying technique known from functional languages. This module, unlike many other modules that borrow techniques from functional languages, doesnt try to make Perl functional. Instead it tries to make currying Perlish.
This module aims to be a base for other modules that use/provide currying techniques.
This module supports a unique set of special spices (argument features). It doesnt just support holes, but also introduces antiholes, blackholes, whiteholes, and antispices. All these extra special spices effect how the spice is applied to the subroutine. They make functions such as &rcurry superfluous. See "Currying" and Sub::Curry::Cookbook.
An oft-missed feature is argument aliasing. This module preserves the aliasing.
Sub::Curry does explicit currying. For more automatic ways to use currying, look in the Sub::Curry::* namespace.
When version hits 1.00 the interface will be stable.
Download (0.006MB)
Added: 2007-05-03 License: Perl Artistic License Price:
905 downloads
B::Terse 5.8.8
B::Terse - Walk Perl syntax tree, printing terse info about ops. more>>
B::Terse - Walk Perl syntax tree, printing terse info about ops.
SYNOPSIS
perl -MO=Terse[,OPTIONS] foo.pl
This version of B::Terse is really just a wrapper that calls B::Concise with the -terse option. It is provided for compatibility with old scripts (and habits) but using B::Concise directly is now recommended instead.
For compatibility with the old B::Terse, this module also adds a method named terse to B::OP and B::SV objects. The B::SV method is largely compatible with the old one, though authors of new software might be advised to choose a more user-friendly output format. The B::OP terse method, however, doesnt work well. Since B::Terse was first written, much more information in OPs has migrated to the scratchpad datastructure, but the terse interface doesnt have any way of getting to the correct pad. As a kludge, the new version will always use the pad for the main program, but for OPs in subroutines this will give the wrong answer or crash.
<<lessSYNOPSIS
perl -MO=Terse[,OPTIONS] foo.pl
This version of B::Terse is really just a wrapper that calls B::Concise with the -terse option. It is provided for compatibility with old scripts (and habits) but using B::Concise directly is now recommended instead.
For compatibility with the old B::Terse, this module also adds a method named terse to B::OP and B::SV objects. The B::SV method is largely compatible with the old one, though authors of new software might be advised to choose a more user-friendly output format. The B::OP terse method, however, doesnt work well. Since B::Terse was first written, much more information in OPs has migrated to the scratchpad datastructure, but the terse interface doesnt have any way of getting to the correct pad. As a kludge, the new version will always use the pad for the main program, but for OPs in subroutines this will give the wrong answer or crash.
Download (12.2MB)
Added: 2007-06-26 License: Perl Artistic License Price:
850 downloads
List::Util 1.19
List::Util Perl module contains a selection of general-utility list subroutines. more>>
List::Util Perl module contains a selection of general-utility list subroutines.
SYNOPSIS
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
List::Util contains a selection of subroutines that people have expressed would be nice to have in the perl core, but the usage would not really be high enough to warrant the use of a keyword, and the size so small such that being individual extensions would be wasteful.
By default List::Util does not export any subroutines. The subroutines defined are
first BLOCK LIST
Similar to grep in that it evaluates BLOCK setting $_ to each element of LIST in turn. first returns the first element where the result from BLOCK is a true value. If BLOCK never returns true or LIST was empty then undef is returned.
$foo = first { defined($_) } @list # first defined value in @list
$foo = first { $_ > $value } @list # first value in @list which
# is greater than $value
This function could be implemented using reduce like this
$foo = reduce { defined($a) ? $a : wanted($b) ? $b : undef } undef, @list
for example wanted() could be defined() which would return the first defined value in @list
max LIST
Returns the entry in the list with the highest numerical value. If the list is empty then undef is returned.
$foo = max 1..10 # 10
$foo = max 3,9,12 # 12
$foo = max @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a > $b ? $a : $b } 1..10
maxstr LIST
Similar to max, but treats all the entries in the list as strings and returns the highest string as defined by the gt operator. If the list is empty then undef is returned.
$foo = maxstr A..Z # Z
$foo = maxstr "hello","world" # "world"
$foo = maxstr @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a gt $b ? $a : $b } A..Z
min LIST
Similar to max but returns the entry in the list with the lowest numerical value. If the list is empty then undef is returned.
$foo = min 1..10 # 1
$foo = min 3,9,12 # 3
$foo = min @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a < $b ? $a : $b } 1..10
minstr LIST
Similar to min, but treats all the entries in the list as strings and returns the lowest string as defined by the lt operator. If the list is empty then undef is returned.
$foo = minstr A..Z # A
$foo = minstr "hello","world" # "hello"
$foo = minstr @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a lt $b ? $a : $b } A..Z
reduce BLOCK LIST
Reduces LIST by calling BLOCK, in a scalar context, multiple times, setting $a and $b each time. The first call will be with $a and $b set to the first two elements of the list, subsequent calls will be done by setting $a to the result of the previous call and $b to the next element in the list.
Returns the result of the last call to BLOCK. If LIST is empty then undef is returned. If LIST only contains one element then that element is returned and BLOCK is not executed.
$foo = reduce { $a < $b ? $a : $b } 1..10 # min
$foo = reduce { $a lt $b ? $a : $b } aa..zz # minstr
$foo = reduce { $a + $b } 1 .. 10 # sum
$foo = reduce { $a . $b } @bar # concat
shuffle LIST
Returns the elements of LIST in a random order
@cards = shuffle 0..51 # 0..51 in a random order
sum LIST
Returns the sum of all the elements in LIST. If LIST is empty then undef is returned.
$foo = sum 1..10 # 55
$foo = sum 3,9,12 # 24
$foo = sum @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a + $b } 1..10
<<lessSYNOPSIS
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
List::Util contains a selection of subroutines that people have expressed would be nice to have in the perl core, but the usage would not really be high enough to warrant the use of a keyword, and the size so small such that being individual extensions would be wasteful.
By default List::Util does not export any subroutines. The subroutines defined are
first BLOCK LIST
Similar to grep in that it evaluates BLOCK setting $_ to each element of LIST in turn. first returns the first element where the result from BLOCK is a true value. If BLOCK never returns true or LIST was empty then undef is returned.
$foo = first { defined($_) } @list # first defined value in @list
$foo = first { $_ > $value } @list # first value in @list which
# is greater than $value
This function could be implemented using reduce like this
$foo = reduce { defined($a) ? $a : wanted($b) ? $b : undef } undef, @list
for example wanted() could be defined() which would return the first defined value in @list
max LIST
Returns the entry in the list with the highest numerical value. If the list is empty then undef is returned.
$foo = max 1..10 # 10
$foo = max 3,9,12 # 12
$foo = max @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a > $b ? $a : $b } 1..10
maxstr LIST
Similar to max, but treats all the entries in the list as strings and returns the highest string as defined by the gt operator. If the list is empty then undef is returned.
$foo = maxstr A..Z # Z
$foo = maxstr "hello","world" # "world"
$foo = maxstr @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a gt $b ? $a : $b } A..Z
min LIST
Similar to max but returns the entry in the list with the lowest numerical value. If the list is empty then undef is returned.
$foo = min 1..10 # 1
$foo = min 3,9,12 # 3
$foo = min @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a < $b ? $a : $b } 1..10
minstr LIST
Similar to min, but treats all the entries in the list as strings and returns the lowest string as defined by the lt operator. If the list is empty then undef is returned.
$foo = minstr A..Z # A
$foo = minstr "hello","world" # "hello"
$foo = minstr @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a lt $b ? $a : $b } A..Z
reduce BLOCK LIST
Reduces LIST by calling BLOCK, in a scalar context, multiple times, setting $a and $b each time. The first call will be with $a and $b set to the first two elements of the list, subsequent calls will be done by setting $a to the result of the previous call and $b to the next element in the list.
Returns the result of the last call to BLOCK. If LIST is empty then undef is returned. If LIST only contains one element then that element is returned and BLOCK is not executed.
$foo = reduce { $a < $b ? $a : $b } 1..10 # min
$foo = reduce { $a lt $b ? $a : $b } aa..zz # minstr
$foo = reduce { $a + $b } 1 .. 10 # sum
$foo = reduce { $a . $b } @bar # concat
shuffle LIST
Returns the elements of LIST in a random order
@cards = shuffle 0..51 # 0..51 in a random order
sum LIST
Returns the sum of all the elements in LIST. If LIST is empty then undef is returned.
$foo = sum 1..10 # 55
$foo = sum 3,9,12 # 24
$foo = sum @bar, @baz # whatever
This function could be implemented using reduce like this
$foo = reduce { $a + $b } 1..10
Download (0.043MB)
Added: 2007-06-30 License: Perl Artistic License Price:
848 downloads
Language::Zcode::Runtime::State 0.8
Language::Zcode::Runtime::State is a Perl module to handle saving, restoring, etc. the game state. more>>
Language::Zcode::Runtime::State is a Perl module to handle saving, restoring, etc. the game state.
restoring
Getter/setter: currently in the process of restoring or not?
start_machine
Start executing the Z-machine.
In the normal case (starting a new game, or restarting), this is as simple as calling the Z-machine subroutine whose address is stored in the header.
If were restoring from a save file, its more complicated. See "resume_execution".
z_call
Wrapper around Z-code subroutine calls. The main reason we need it is for save/restore.
In the normal case, z_call just calls the Z-code subroutine at address arg0 with the given args (arg5-argn), if any. Args 1-4 arent used by z_call, but (hack alert!) they go into the Perl call stack, which is needed for saving Z-machine state.
Input: subroutine address to call, local variables & eval stack (arrayrefs), next PC, store variable, args to the Z-sub.
See "The call stack" for far more detail on this sub and save/restore.
save_state
Implement the @save opcode, saving the current Z-machine state (as opposed to writing a table to a file, the other use of the @save opcode)
Note that this sub also gets called at the very end of the restoring process.
Returns 0 for failed save, 1 for successful save, 2 for "just finished restoring".
build_save_stack
Create a Z-machine call stack by peeking at the Perl call stack.
When calling Z_machine subroutines, we call z_call with all the information contained in a Z stack frame. We retrieve that information from the Perl call stack and build a Z-machine call stack with it.
restore_state
Implement the @restore opcode, restoring the current Z-machine state (as opposed to reading a table from a file, the other use of the @restore opcode)
<<lessrestoring
Getter/setter: currently in the process of restoring or not?
start_machine
Start executing the Z-machine.
In the normal case (starting a new game, or restarting), this is as simple as calling the Z-machine subroutine whose address is stored in the header.
If were restoring from a save file, its more complicated. See "resume_execution".
z_call
Wrapper around Z-code subroutine calls. The main reason we need it is for save/restore.
In the normal case, z_call just calls the Z-code subroutine at address arg0 with the given args (arg5-argn), if any. Args 1-4 arent used by z_call, but (hack alert!) they go into the Perl call stack, which is needed for saving Z-machine state.
Input: subroutine address to call, local variables & eval stack (arrayrefs), next PC, store variable, args to the Z-sub.
See "The call stack" for far more detail on this sub and save/restore.
save_state
Implement the @save opcode, saving the current Z-machine state (as opposed to writing a table to a file, the other use of the @save opcode)
Note that this sub also gets called at the very end of the restoring process.
Returns 0 for failed save, 1 for successful save, 2 for "just finished restoring".
build_save_stack
Create a Z-machine call stack by peeking at the Perl call stack.
When calling Z_machine subroutines, we call z_call with all the information contained in a Z stack frame. We retrieve that information from the Perl call stack and build a Z-machine call stack with it.
restore_state
Implement the @restore opcode, restoring the current Z-machine state (as opposed to reading a table from a file, the other use of the @restore opcode)
Download (0.29MB)
Added: 2007-07-05 License: Perl Artistic License Price:
844 downloads
Getopt::Function 0.017
Getopt::Function is a Perl module to provide mixed options with help information. more>>
Getopt::Function is a Perl module to provide mixed options with help information.
SYNOPSIS
use Getopt::Function qw(maketrue makevalue);
$::opthandler = new Getopt::Function
[ ], { => [ , ,
] }
$result = GetOptions (...option-descriptions...);
$::opthandler->std_opts;
$::opthandler->check_opts;
The aim of this module is to make it easy to provide sophisticated and complex interfaces to commands in a simple to use and clear manner with proper help facilities.
It is designed to do this by making it possible to write the options, with documentation and subroutines to implement them, directly into a hash and then call the appropriate ones as options detected on the command line.
<<lessSYNOPSIS
use Getopt::Function qw(maketrue makevalue);
$::opthandler = new Getopt::Function
[ ], { => [ , ,
] }
$result = GetOptions (...option-descriptions...);
$::opthandler->std_opts;
$::opthandler->check_opts;
The aim of this module is to make it easy to provide sophisticated and complex interfaces to commands in a simple to use and clear manner with proper help facilities.
It is designed to do this by making it possible to write the options, with documentation and subroutines to implement them, directly into a hash and then call the appropriate ones as options detected on the command line.
Download (0.013MB)
Added: 2006-10-30 License: Perl Artistic License Price:
1089 downloads
Tie::Layers 0.06
Tie::Layers is a Perl module to read and write files pipelined through a stack of subroutine layers. more>>
SYNOPSIS
#####
# Subroutines
#
use Tie::Layers qw(is_handle config);
$yes = is_handle( $file_handle );
($key, $old_value) = config(%options, $key);
($key, $old_value) = config(%options, $key => $new_value );
####
# Config default startup options
#
@old_options_list = config(%options, @option_list);
@old_options_list = config(%options, @option_list);
@old_options_list = config(%options, %option_list);
#####
# Class interface
#
require Tie::Layers;
#####
# Using support methods and file handle with
# the file subroutines such as open(), readline()
# print(), close()
#
tie *LAYERS_FILEHANDLE, Tie::Layers, @options
$layers = tied *LAYERS_FILEHANDLE;
#####
# Using support methods only, no file subroutines
#
$layers = Tie::Layers->TIEHANDLE(@options);
($key, $old_value) = $layers->config($key);
($key, $old_value) = $layers->config($key => $new_value );
@old_options_list = $layers->config(@option_list);
@old_options_list = $layers->config(@option_list);
@old_options_list = $layers->config(%option_list);
$data = $layers->fin($filename, @options);
$data = $layers->fout($filename, $data, @options);
$yes = $layers->is_handle( $file_handle );
If a subroutine or method will process a list of options, @options, that subroutine will also process an array reference, @options, [@options], or hash reference, %options, {@options}.
The Tie::Layers program module contains the tie file handle Tie::Layers package. The Tie::Layers package provides the ability to insert a stack of subroutines between file subroutines print and realine and the underlying $file. The syntax of the subroutines of each layer of the readline stack and the print stack must comply to the the requirements described herein below.
This is necessary so that the Tie::Layers READLINE and PRINT subroutines know how to transfer the output from one layer to the input of another layer. The stacks are setup by supplying options with a reference to the subroutine for each layer in the print stack and the readline stack. The Tie::Layers are line orientated and do not support any character file subrouintes.
The getc, read, and write file subroutines are supported by the Tie::Layers package. The seek routines are line oriented in that the seek and tell subroutine positions are the line in the underlying file and not the character position in the file.
Download (0.070MB)
Added: 2007-02-13 License: Perl Artistic License Price:
983 downloads
Class::Std::Utils 0.0.2
Class::Std::Utils is a Perl module for utility subroutines for building inside-out objects. more>>
Class::Std::Utils is a Perl module for utility subroutines for building "inside-out" objects.
SYNOPSIS
use Class::Std::Utils;
# Constructor for anonymous scalars...
my $new_object = bless anon_scalar(), $class;
# Convert an object reference into a unique ID number...
my $ID_num = ident $new_object;
# Extract class-specific arguments from a hash reference...
my %args = extract_initializers_from($arg_ref);
This module provides three utility subroutines that simplify the creation of "inside-out" classes. See Chapters 15 and 16 of "Perl Best Practices" (OReilly, 2005) for details.
<<lessSYNOPSIS
use Class::Std::Utils;
# Constructor for anonymous scalars...
my $new_object = bless anon_scalar(), $class;
# Convert an object reference into a unique ID number...
my $ID_num = ident $new_object;
# Extract class-specific arguments from a hash reference...
my %args = extract_initializers_from($arg_ref);
This module provides three utility subroutines that simplify the creation of "inside-out" classes. See Chapters 15 and 16 of "Perl Best Practices" (OReilly, 2005) for details.
Download (0.005MB)
Added: 2006-09-02 License: Perl Artistic License Price:
1147 downloads
Async::Group 0.3
Async::Group is a Perl class to deal with simultaneous asynchronous calls. more>>
Async::Group is a Perl class to deal with simultaneous asynchronous calls.
SYNOPSIS
use Async::Group ;
use strict ;
sub sub1
{
print "Dummy subroutine n";
my $dummy = shift ;
my $cb = shift ;
&$cb(1);
}
sub allDone
{
print "All done, result is ", shift ,"n" ;
}
my $a = Async::Group->new(name => aTest, test => 1) ;
$a->run(set => [ sub {⊂1( callback => sub {$a->callDone(@_)} )},
sub {⊂1( callback => sub {$a->callDone(@_)} )} ],
callback => &allDone
)
# or another way which avoids the clumsy nested subs
my $cb = $a->getCbRef();
$a->run(set => [ sub {⊂1( callback => $cb)},
sub {⊄1( callback => $cb )} ],
callback => &allDone
)
If you sometimes have to launch several asynchronous calls in parrallel and want to call one call-back function when all these calls are finished, this module may be for you.
Async::Group is a class which enables you to call several asynchronous routines. Each routine may have their own callback. When all the routine are over (i.e. all their callback were called), Async::Group will call the global callback given by the user.
Note that one Async::Group objects must be created for each group of parrallel calls. This object may be destroyed (or will vanish itself) once the global callback is called.
Note also that Async::Group does not perform any fork or other system calls. It just run the passed subroutines and keep count of the call-back functions called by the aforementionned subroutines. When all these subs are finished, it calls another call-back (passed by the user) to perform whatever function required by the user.
Using fork or threads or whatever is left to the user.
<<lessSYNOPSIS
use Async::Group ;
use strict ;
sub sub1
{
print "Dummy subroutine n";
my $dummy = shift ;
my $cb = shift ;
&$cb(1);
}
sub allDone
{
print "All done, result is ", shift ,"n" ;
}
my $a = Async::Group->new(name => aTest, test => 1) ;
$a->run(set => [ sub {⊂1( callback => sub {$a->callDone(@_)} )},
sub {⊂1( callback => sub {$a->callDone(@_)} )} ],
callback => &allDone
)
# or another way which avoids the clumsy nested subs
my $cb = $a->getCbRef();
$a->run(set => [ sub {⊂1( callback => $cb)},
sub {⊄1( callback => $cb )} ],
callback => &allDone
)
If you sometimes have to launch several asynchronous calls in parrallel and want to call one call-back function when all these calls are finished, this module may be for you.
Async::Group is a class which enables you to call several asynchronous routines. Each routine may have their own callback. When all the routine are over (i.e. all their callback were called), Async::Group will call the global callback given by the user.
Note that one Async::Group objects must be created for each group of parrallel calls. This object may be destroyed (or will vanish itself) once the global callback is called.
Note also that Async::Group does not perform any fork or other system calls. It just run the passed subroutines and keep count of the call-back functions called by the aforementionned subroutines. When all these subs are finished, it calls another call-back (passed by the user) to perform whatever function required by the user.
Using fork or threads or whatever is left to the user.
Download (0.004MB)
Added: 2007-04-12 License: Perl Artistic License Price:
925 downloads
Attribute::Handlers 0.85
Attribute::Handlers is a multi-purpose, highly customizable Linux programming tool. more>> Attribute:Handlers 0.85 is a multi-purpose, highly customizable Linux programming tool. This module, when inherited by a package, allows that package's class to define attribute handler subroutines for specific attributes. Variables and subroutines subsequently defined in that package, or in packages derived from that package may be given attributes with the same names as the attribute handler subroutines, which will then be called in one of the compilation phases (i.e. in a BEGIN, CHECK, INIT, or END block). (UNITCHECK blocks don't correspond to a global compilation phase, so they can't be specified here.)
To create a handler, define it as a subroutine with the same name as the desired attribute, and declare the subroutine itself with the attribute.
Added: 2009-07-26 License: Perl Artistic License Price: FREE
downloads
Ace::Browser::AceSubs 1.91
Ace::Browser::AceSubs Perl module contains subroutines for AceBrowser. more>>
Ace::Browser::AceSubs Perl module contains subroutines for AceBrowser.
SYNOPSIS
use Ace;
use Ace::Browser::AceSubs;
use CGI qw(:standard);
use CGI::Cookie;
my $obj = GetAceObject() || AceNotFound();
PrintTop($obj);
print $obj->asHTML;
PrintBottom();
Ace::Browser::AceSubs exports a set of routines that are useful for creating search pages and displays for AceBrowser CGI pages. See http://stein.cshl.org/AcePerl/AceBrowser.
The following subroutines are exported by default:
AceError
AceMissing
AceNotFound
Configuration
DoRedirect
GetAceObject
Object2URL
ObjectLink
OpenDatabase
PrintTop
PrintBottom
Url
The following subroutines are exported if explicitly requested:
AceAddCookie
AceInit
AceHeader
AceMultipleChoices
AceRedirect
DB_Name
Footer
Header
ResolveUrl
Style
Toggle
TypeSelector
To load the default subroutines load the module with:
use Ace::Browser::AceSubs;
To bring in a set of optionally routines, load the module with:
use Ace::Browser::AceSubs qw(AceInit AceRedirect);
To bring in all the default subroutines, plus some of the optional ones:
use Ace::Browser::AceSubs qw(:DEFAULT AceInit AceRedirect);
There are two main types of AceBrowser scripts:
display scripts
These are called with the CGI parameters b and b , corresponding to the name and class of an AceDB object to display. The subroutine GetAceObject() will return the requested object, or undef if the object does not exist.
To retrieve the parameters, use the CGI.pm param() method:
$name = param(name);
$class = param(class);
search scripts
These are not called with any CGI parameters on their first invocation, but can define their own parameter lists by creating fill-out forms. The AceBrowser system remembers the last search performed by a search script in a cookie and regenerates the CGI parameters the next time the user selects that search script.
<<lessSYNOPSIS
use Ace;
use Ace::Browser::AceSubs;
use CGI qw(:standard);
use CGI::Cookie;
my $obj = GetAceObject() || AceNotFound();
PrintTop($obj);
print $obj->asHTML;
PrintBottom();
Ace::Browser::AceSubs exports a set of routines that are useful for creating search pages and displays for AceBrowser CGI pages. See http://stein.cshl.org/AcePerl/AceBrowser.
The following subroutines are exported by default:
AceError
AceMissing
AceNotFound
Configuration
DoRedirect
GetAceObject
Object2URL
ObjectLink
OpenDatabase
PrintTop
PrintBottom
Url
The following subroutines are exported if explicitly requested:
AceAddCookie
AceInit
AceHeader
AceMultipleChoices
AceRedirect
DB_Name
Footer
Header
ResolveUrl
Style
Toggle
TypeSelector
To load the default subroutines load the module with:
use Ace::Browser::AceSubs;
To bring in a set of optionally routines, load the module with:
use Ace::Browser::AceSubs qw(AceInit AceRedirect);
To bring in all the default subroutines, plus some of the optional ones:
use Ace::Browser::AceSubs qw(:DEFAULT AceInit AceRedirect);
There are two main types of AceBrowser scripts:
display scripts
These are called with the CGI parameters b and b , corresponding to the name and class of an AceDB object to display. The subroutine GetAceObject() will return the requested object, or undef if the object does not exist.
To retrieve the parameters, use the CGI.pm param() method:
$name = param(name);
$class = param(class);
search scripts
These are not called with any CGI parameters on their first invocation, but can define their own parameter lists by creating fill-out forms. The AceBrowser system remembers the last search performed by a search script in a cookie and regenerates the CGI parameters the next time the user selects that search script.
Download (0.29MB)
Added: 2007-07-20 License: Perl Artistic License Price:
826 downloads
Devel::Profile 1.04
Devel::Profile is a Perl module to tell me why my perl program runs so slowly. more>>
Devel::Profile is a Perl module to tell me why my perl program runs so slowly.
SYNOPSIS
perl -d:Profile program.pl
less prof.out
The Devel::Profile package is a Perl code profiler. This will collect information on the execution time of a Perl script and of the subs in that script. This information can be used to determine which subroutines are using the most time and which subroutines are being called most often.
To profile a Perl script, run the perl interpreter with the -d debugging switch. The profiler uses the debugging hooks. So to profile script test.pl the following command should be used:
perl -d:Profile test.pl
When the script terminates (or periodicly while running, see ENVIRONMENT) the profiler will dump the profile information to a file called prof.out. This file is human-readable, no additional tool is required to read it.
Note: Statistics are kept per sub, not per line.
<<lessSYNOPSIS
perl -d:Profile program.pl
less prof.out
The Devel::Profile package is a Perl code profiler. This will collect information on the execution time of a Perl script and of the subs in that script. This information can be used to determine which subroutines are using the most time and which subroutines are being called most often.
To profile a Perl script, run the perl interpreter with the -d debugging switch. The profiler uses the debugging hooks. So to profile script test.pl the following command should be used:
perl -d:Profile test.pl
When the script terminates (or periodicly while running, see ENVIRONMENT) the profiler will dump the profile information to a file called prof.out. This file is human-readable, no additional tool is required to read it.
Note: Statistics are kept per sub, not per line.
Download (0.007MB)
Added: 2006-10-03 License: Perl Artistic License Price:
1116 downloads
Secleted [ 0 ] software to compare
Copyright Notice:
Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future software development. The above subroutines search only lists software in full, demo and trial versions for free download. Download links are directly from our mirror sites or publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed