subroutine
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 247
Sub::Timebound 1.01
Sub::Timebound is a Perl extension for timebound computations. more>>
Sub::Timebound is a Perl extension for timebound computations.
SYNOPSIS
use Sub::Timebound;
sub fun
{
my $i = shift;
if ($i =~ /7$/) {
die "Simulated internal errorn";
}
while ($i) {
$i--;
}
return "All is well";
}
my $x = timeboundretry(10, 3, 5, &fun, 10);
### Returns { value => ..., status => 0(FAILURE)/1(SUCCESS) }
### value is the return value of fun()
if ($x->{status}) {
# SUCCESS
$x->{value}
} else {
# FAILURE
}
Module exports "timeboundretry" - this is a wrapper that watches a function call.
my $x = timeboundretry([TimeAllocated], [NumberOfAttempts],
[PauseBetweenAttempts],[CodeRef],[Param1], [Param2], ...);
[TimeAllocated] - Seconds allocated to [CodeRef] to complete
[NumberOfAttempts] - Number of attempts made to [CodeRef]
[PauseBetweenAttempts] - Seconds to wait before making subsequent attempts
[CodeRef] - Reference to subroutine
[Param1]... - Parameters to subroutine
<<lessSYNOPSIS
use Sub::Timebound;
sub fun
{
my $i = shift;
if ($i =~ /7$/) {
die "Simulated internal errorn";
}
while ($i) {
$i--;
}
return "All is well";
}
my $x = timeboundretry(10, 3, 5, &fun, 10);
### Returns { value => ..., status => 0(FAILURE)/1(SUCCESS) }
### value is the return value of fun()
if ($x->{status}) {
# SUCCESS
$x->{value}
} else {
# FAILURE
}
Module exports "timeboundretry" - this is a wrapper that watches a function call.
my $x = timeboundretry([TimeAllocated], [NumberOfAttempts],
[PauseBetweenAttempts],[CodeRef],[Param1], [Param2], ...);
[TimeAllocated] - Seconds allocated to [CodeRef] to complete
[NumberOfAttempts] - Number of attempts made to [CodeRef]
[PauseBetweenAttempts] - Seconds to wait before making subsequent attempts
[CodeRef] - Reference to subroutine
[Param1]... - Parameters to subroutine
Download (0.004MB)
Added: 2007-05-03 License: Perl Artistic License Price:
905 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
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
Params::Profile 0.10
Params::Profile is a Perl module for registering Parameter profiles. more>>
Params::Profile is a Perl module for registering Parameter profiles.
SYNOPSIS
package Foo::Bar;
use Params::Profile;
### Single profile
Params::Profile->register_profile(
method => subroto,
profile => {
testkey1 => { required => 1 },
testkey2 => {
required => 1,
allow => qr/^d+$/,
},
testkey3 => {
allow => qr/^w+$/,
},
},
);
sub subroto {
my (%params) = @_;
return unlesss Params::Profile->validate(params => %params);
### DO SOME STUFF HERE ...
}
my $profile = Params::Profile->get_profile(method => subroto);
### Multiple Profile
Params::Profile->register_profile(
method => subalso,
profile => [
subroto,
{
testkey4 => { required => 1 },
testkey5 => {
required => 1,
allow => qr/^d+$/,
},
testkey6 => {
allow => qr/^w+$/,
},
},
],
);
sub subalso {
my (%params) = @_;
### Checks parameters agains profile of subroto and above registered
### profile
return unlesss Params::Profile->validate(params => %params);
### DO SOME STUFF HERE ...
}
Params::Profile provides a mechanism for a centralised Params::Check or a Data::FormValidater profile. You can bind a profile to a class::subroutine, then, when you are in a subroutine you can simply call Params::Profile->check($params) of Params::Profile->validate($params) to validate against this profile. Validate will return true or false on successfull or failed validation. Check will return what Data::FormValidator or Params::Check would return. (For Params::Check this is simply a hash with the validated parameters , for Data::FormValidator, this is a Data::FormValidator::Results object)
<<lessSYNOPSIS
package Foo::Bar;
use Params::Profile;
### Single profile
Params::Profile->register_profile(
method => subroto,
profile => {
testkey1 => { required => 1 },
testkey2 => {
required => 1,
allow => qr/^d+$/,
},
testkey3 => {
allow => qr/^w+$/,
},
},
);
sub subroto {
my (%params) = @_;
return unlesss Params::Profile->validate(params => %params);
### DO SOME STUFF HERE ...
}
my $profile = Params::Profile->get_profile(method => subroto);
### Multiple Profile
Params::Profile->register_profile(
method => subalso,
profile => [
subroto,
{
testkey4 => { required => 1 },
testkey5 => {
required => 1,
allow => qr/^d+$/,
},
testkey6 => {
allow => qr/^w+$/,
},
},
],
);
sub subalso {
my (%params) = @_;
### Checks parameters agains profile of subroto and above registered
### profile
return unlesss Params::Profile->validate(params => %params);
### DO SOME STUFF HERE ...
}
Params::Profile provides a mechanism for a centralised Params::Check or a Data::FormValidater profile. You can bind a profile to a class::subroutine, then, when you are in a subroutine you can simply call Params::Profile->check($params) of Params::Profile->validate($params) to validate against this profile. Validate will return true or false on successfull or failed validation. Check will return what Data::FormValidator or Params::Check would return. (For Params::Check this is simply a hash with the validated parameters , for Data::FormValidator, this is a Data::FormValidator::Results object)
Download (0.006MB)
Added: 2007-04-11 License: Perl Artistic License Price:
926 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
Blatte::Builtins 0.9.4
Blatte::Builtins is a Perl module with Blatte-callable intrinsics. more>>
Blatte::Builtins is a Perl module with Blatte-callable intrinsics.
SYNOPSIS
package MyPackage;
use Blatte::Builtins;
eval(...compiled Blatte program...);
This module defines the standard Blatte-callable intrinsic functions.
A Blatte intrinsic is simply a Perl subroutine that (a) has been assigned (by reference) to a scalar variable (whose name begins with a letter), and (b) takes a hash reference as its first argument, in which named parameter values are passed.
<<lessSYNOPSIS
package MyPackage;
use Blatte::Builtins;
eval(...compiled Blatte program...);
This module defines the standard Blatte-callable intrinsic functions.
A Blatte intrinsic is simply a Perl subroutine that (a) has been assigned (by reference) to a scalar variable (whose name begins with a letter), and (b) takes a hash reference as its first argument, in which named parameter values are passed.
Download (0.031MB)
Added: 2007-04-19 License: Perl Artistic License Price:
918 downloads
Sub::PatMat 0.01
Sub::PatMat can call a version of subroutine depending on its arguments. more>>
Sub::PatMat can call a version of subroutine depending on its arguments.
SYNOPSIS
use Sub::PatMat;
# basics:
sub fact : when($_[0] $b) { 1 }
print join ", ", sort mysort (3,1,2);
# intuiting parameter names:
sub dispatch : when($ev eq "help") { my ($ev) = @_; print "helpn" }
sub dispatch : when($ev eq "blah") { my ($ev) = @_; print "blahn" }
dispatch("help");
dispatch("blah");
# no fallback, this will die:
dispatch("hest"); # dies with "Bad match"
# silly
sub do_something : when(full_moon()) { do_one_thing() }
sub do_something { do_something_else() }
The Sub::PatMat module provides the programmer with the ability to define a subroutine multiple times and to specify what version of the subroutine should be called, depending on the parameters passed to it (or any other condition).
This is somewhat similar to argument pattern matching facility provided by many programming languages.
To use argument pattern matching on a sub, the programmer has to specify the when attribute. The parameter to the attribute must be a single Perl expression.
When the sub is called, those expressions are evaluated consequitively until one of them evaluates to a true value. When this happens, the corresponding version of a sub is called.
If none of the expressions evaluates to a true value, a Bad Match exception is thrown.
It is possible to specify a fall-back version of the function by doing one of the following:
specifying when without an expression
specifying when with an empty expression
not specifying the when attribute at all
Please note that it does not make sense to specify any non-fall-back version of the sub after the fall-back version, since such will never be called.
There is an additional limitation for the last form of the fall-back version (the one without the when attribute at all), namely, it must be the last version of the sub defined.
It is possible to specify named sub parameters in the when-expression. This facility is highly experimental and is currently limited to scalar parameters only. The named sub parameters are extracted from expressions of the form
my (parameter list) = @_;
anywhere in the body of the sub.
Version restrictions:
- The ability to intuit parameter names is very limited and without doubts buggy.
- The when attribute condition is limited to a single Perl expression.
Enhancements:
- Perl
<<lessSYNOPSIS
use Sub::PatMat;
# basics:
sub fact : when($_[0] $b) { 1 }
print join ", ", sort mysort (3,1,2);
# intuiting parameter names:
sub dispatch : when($ev eq "help") { my ($ev) = @_; print "helpn" }
sub dispatch : when($ev eq "blah") { my ($ev) = @_; print "blahn" }
dispatch("help");
dispatch("blah");
# no fallback, this will die:
dispatch("hest"); # dies with "Bad match"
# silly
sub do_something : when(full_moon()) { do_one_thing() }
sub do_something { do_something_else() }
The Sub::PatMat module provides the programmer with the ability to define a subroutine multiple times and to specify what version of the subroutine should be called, depending on the parameters passed to it (or any other condition).
This is somewhat similar to argument pattern matching facility provided by many programming languages.
To use argument pattern matching on a sub, the programmer has to specify the when attribute. The parameter to the attribute must be a single Perl expression.
When the sub is called, those expressions are evaluated consequitively until one of them evaluates to a true value. When this happens, the corresponding version of a sub is called.
If none of the expressions evaluates to a true value, a Bad Match exception is thrown.
It is possible to specify a fall-back version of the function by doing one of the following:
specifying when without an expression
specifying when with an empty expression
not specifying the when attribute at all
Please note that it does not make sense to specify any non-fall-back version of the sub after the fall-back version, since such will never be called.
There is an additional limitation for the last form of the fall-back version (the one without the when attribute at all), namely, it must be the last version of the sub defined.
It is possible to specify named sub parameters in the when-expression. This facility is highly experimental and is currently limited to scalar parameters only. The named sub parameters are extracted from expressions of the form
my (parameter list) = @_;
anywhere in the body of the sub.
Version restrictions:
- The ability to intuit parameter names is very limited and without doubts buggy.
- The when attribute condition is limited to a single Perl expression.
Enhancements:
- Perl
Download (0.014MB)
Added: 2007-08-07 License: Perl Artistic License Price:
808 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
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
Include 1.02a
Include is a Perl module that allow you to use #defines from C header files. more>>
Include is a Perl module that allow you to use #defines from C header files.
SYNOPSIS
use Include qw(-I /some/path/of/mine);
use Include q< sys/types.h >;
use Include q< sys/types.h > "/[A-Z]/";
The Include module implements a method of using #define constants from C header files. It does this by putting an extra level of indirection on the use operator.
To enhance performance a cache scheme is used. When a new module is required the cache is checked first, if the package is not found then it will be generated from the C header files.
Include can be configured to place any generated packages into the cache automatically, for security reasons this is turned off by default.
There are three ways in which the use Include statement can be used.
use Include qw(-I /some/path/of/mine);
Will unshift the directory /some/path/of/mine onto the search path used so that subsequent searches for .h header files will search the given directories first.
use Include q< sys/types.h >;
use Include q< sys/types.h > "/[A-Z]/";
Both of these will define all the constants found in and any header files included by it. The first will export all of these into the calling package, but the second will only export defined macros that contain an unppercase character.
Subroutines
Under normal use the Include package is only used via the use/import interface. But there are some routines that are defined.
CacheOn
This subroutine will cause the Include module to save any generated packages into the cache.
Generate( @headers )
This subroutine will force the generation of the given header files, and any files included in them, reguardless of whether they are currently in the cache. If cache writing is turned on then the cache files will be overwritten.
Search( @dirs )
This subroutine will unshift the given directories onto the search path used for locating the header files.
<<lessSYNOPSIS
use Include qw(-I /some/path/of/mine);
use Include q< sys/types.h >;
use Include q< sys/types.h > "/[A-Z]/";
The Include module implements a method of using #define constants from C header files. It does this by putting an extra level of indirection on the use operator.
To enhance performance a cache scheme is used. When a new module is required the cache is checked first, if the package is not found then it will be generated from the C header files.
Include can be configured to place any generated packages into the cache automatically, for security reasons this is turned off by default.
There are three ways in which the use Include statement can be used.
use Include qw(-I /some/path/of/mine);
Will unshift the directory /some/path/of/mine onto the search path used so that subsequent searches for .h header files will search the given directories first.
use Include q< sys/types.h >;
use Include q< sys/types.h > "/[A-Z]/";
Both of these will define all the constants found in and any header files included by it. The first will export all of these into the calling package, but the second will only export defined macros that contain an unppercase character.
Subroutines
Under normal use the Include package is only used via the use/import interface. But there are some routines that are defined.
CacheOn
This subroutine will cause the Include module to save any generated packages into the cache.
Generate( @headers )
This subroutine will force the generation of the given header files, and any files included in them, reguardless of whether they are currently in the cache. If cache writing is turned on then the cache files will be overwritten.
Search( @dirs )
This subroutine will unshift the given directories onto the search path used for locating the header files.
Download (0.006MB)
Added: 2007-05-09 License: Perl Artistic License Price:
902 downloads
IO::Interactive 0.0.3
IO::Interactive is a Perl module with utilities for interactive I/O. more>>
IO::Interactive is a Perl module with utilities for interactive I/O.
SYNOPSIS
use IO::Interactive qw(is_interactive interactive busy);
if ( is_interactive() ) {
print "Running interactivelyn";
}
# or...
print {interactive} "Running interactivelyn";
$fh = busy {
do_noninteractive_stuff();
}
This module provides three utility subroutines that make it easier to develop interactive applications...
is_interactive()
This subroutine returns true if *ARGV and *STDOUT are connected to the terminal. The test is considerably more sophisticated than:
-t *ARGV && -t *STDOUT
as it takes into account the magic behaviour of *ARGV.
You can also pass is_interactive a writable filehandle, in which case it requires that filehandle be connected to a terminal (instead of *STDOUT). The usual suspect here is *STDERR:
if ( is_interactive(*STDERR) ) {
carp $warning;
}
interactive()
This subroutine returns *STDOUT if is_interactive is true. If is_interactive() is false, interactive returns a filehandle that does not print.
This makes it easy to create applications that print out only when the application is interactive:
print {interactive} "Please enter a value: ";
my $value = ;
You can also pass interactive a writable filehandle, in which case it writes to that filehandle if it is connected to a terminal (instead of writinbg to *STDOUT). Once again, the usual suspect is *STDERR:
print {interactive(*STDERR)} $warning;
busy {...}
This subroutine takes a block as its single argument and executes that block. Whilst the block is executed, *ARGV is temporarily replaced by a closed filehandle. That is, no input from *ARGV is possible in a busy block. Furthermore, any attempts to send input into the busy block through *ARGV is intercepted and a warning message is printed to *STDERR. The busy call returns a filehandle that contains the intercepted input.
A busy block is therefore useful to prevent attempts at input when the program is busy at some non-interactive task.
<<lessSYNOPSIS
use IO::Interactive qw(is_interactive interactive busy);
if ( is_interactive() ) {
print "Running interactivelyn";
}
# or...
print {interactive} "Running interactivelyn";
$fh = busy {
do_noninteractive_stuff();
}
This module provides three utility subroutines that make it easier to develop interactive applications...
is_interactive()
This subroutine returns true if *ARGV and *STDOUT are connected to the terminal. The test is considerably more sophisticated than:
-t *ARGV && -t *STDOUT
as it takes into account the magic behaviour of *ARGV.
You can also pass is_interactive a writable filehandle, in which case it requires that filehandle be connected to a terminal (instead of *STDOUT). The usual suspect here is *STDERR:
if ( is_interactive(*STDERR) ) {
carp $warning;
}
interactive()
This subroutine returns *STDOUT if is_interactive is true. If is_interactive() is false, interactive returns a filehandle that does not print.
This makes it easy to create applications that print out only when the application is interactive:
print {interactive} "Please enter a value: ";
my $value = ;
You can also pass interactive a writable filehandle, in which case it writes to that filehandle if it is connected to a terminal (instead of writinbg to *STDOUT). Once again, the usual suspect is *STDERR:
print {interactive(*STDERR)} $warning;
busy {...}
This subroutine takes a block as its single argument and executes that block. Whilst the block is executed, *ARGV is temporarily replaced by a closed filehandle. That is, no input from *ARGV is possible in a busy block. Furthermore, any attempts to send input into the busy block through *ARGV is intercepted and a warning message is printed to *STDERR. The busy call returns a filehandle that contains the intercepted input.
A busy block is therefore useful to prevent attempts at input when the program is busy at some non-interactive task.
Download (0.005MB)
Added: 2007-01-16 License: Perl Artistic License Price:
1011 downloads
Test::Stochastic 0.03
Test::Stochastic is a Perl module to check probabilities of randomized methods. more>>
Test::Stochastic is a Perl module to check probabilities of randomized methods.
SYNOPSIS
use Test::Stochastic qw(stochastic_ok);
stochastic_ok sub { ...random sub...}, {a => 0.4, b => 0.6};
stochastic_ok {a => 0.4, b => 0.6}, sub { ...random sub...};
Test::Stochastic::setup(times => 100, tolerence => 0.1);
This module can be used to check the probability distribution of answers given by a method. The code fragments in the synopsis above check that the subroutine passed to stochastic_ok returns a with probability 0.4, and b with probability 0.6.
This module will work only if the return values are numbers or strings. Future versions will handle references as well.
<<lessSYNOPSIS
use Test::Stochastic qw(stochastic_ok);
stochastic_ok sub { ...random sub...}, {a => 0.4, b => 0.6};
stochastic_ok {a => 0.4, b => 0.6}, sub { ...random sub...};
Test::Stochastic::setup(times => 100, tolerence => 0.1);
This module can be used to check the probability distribution of answers given by a method. The code fragments in the synopsis above check that the subroutine passed to stochastic_ok returns a with probability 0.4, and b with probability 0.6.
This module will work only if the return values are numbers or strings. Future versions will handle references as well.
Download (0.004MB)
Added: 2007-08-14 License: Perl Artistic License Price:
801 downloads
Tie::Form 0.02
Tie::Form is a Perl module to access a machine readable database file that minics a hardcopy form. more>>
Tie::Form is a Perl module to access a machine readable database file that minics a hardcopy form.
SYNOPSIS
require Tie::Form;
#####
# Using support methods and file handle with
# the file subroutines such as open(), readline()
# print(), close()
#
tie *FORM_FILEHANDLE, Tie::Form, @options
$form = tied *FORM_FILEHANDLE;
#####
# Using support methods only, no file subroutines
#
$form = Tie::Form->new(@options);
$encoded_fields = $form->decode_record($record);
@fields = $form->decode_field($encoded_fields);
$encoded_fields = $form->encode_field (@fields);
$record = $form->encode_record($encoded_fields);
$record = $form->get_record();
####
# Subroutine interface
#
$encoded_fields = decode_record($record);
@fields = decode_field($encoded_fields);
$encoded_fields = encode_field (@fields);
$record = encode_record($encoded_fields);
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}.
<<lessSYNOPSIS
require Tie::Form;
#####
# Using support methods and file handle with
# the file subroutines such as open(), readline()
# print(), close()
#
tie *FORM_FILEHANDLE, Tie::Form, @options
$form = tied *FORM_FILEHANDLE;
#####
# Using support methods only, no file subroutines
#
$form = Tie::Form->new(@options);
$encoded_fields = $form->decode_record($record);
@fields = $form->decode_field($encoded_fields);
$encoded_fields = $form->encode_field (@fields);
$record = $form->encode_record($encoded_fields);
$record = $form->get_record();
####
# Subroutine interface
#
$encoded_fields = decode_record($record);
@fields = decode_field($encoded_fields);
$encoded_fields = encode_field (@fields);
$record = encode_record($encoded_fields);
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}.
Download (0.087MB)
Added: 2007-02-16 License: Perl Artistic License Price:
980 downloads
Algorithm::Hamming::Perl 0.05
Algorithm::Hamming::Perl is a Perl implementation of ECC Hamming encoding, for single bit auto error correction. more>>
Algorithm::Hamming::Perl is a Perl implementation of ECC Hamming encoding, for single bit auto error correction.
SYNOPSIS
use Algorithm::Hamming::Perl qw(hamming unhamming);
$code = hamming($data); # Encode $data
$data = unhamming($code); # Decode and fix errors ($data,$errors) = unhamming($code); # + return error count
This is an Error Correction Code module, implementing Hamming encoding (8 bits data, 4 bits Hamming - ie increases data size by 50%). Data can be encoded so that single bit errors within a byte are auto-corrected.
This may be useful as a precaution before storing or sending data where single bit errors are expected.
Hamming encoding was invented by Richard Hamming, Bell Labs, during 1948.
EXPORT SUBROUTINES
hamming (SCALAR)
Returns the Hamming code from the provided input data.
unhamming (SCALAR)
Returns the original data from the provided Hamming code. Single bit errors are auto corrected.
unhamming_err (SCALAR)
Returns the original data from the provided Hamming code, and a number counting the number of bytes that were corrected. Single bit errors are auto corrected.
OTHER SUBROUTINES
Algorithm::Hamming::Perl::hamming_faster ()
This is an optional subroutine that will speed Hamming encoding if it is run once at the start of the program. It does this by using a larger (hash) cache of preprocessed results. The disadvantage is that it uses more memory, and can add several seconds to invocation time. Only use this if you are encoding more than 1 Mb of data.
<<lessSYNOPSIS
use Algorithm::Hamming::Perl qw(hamming unhamming);
$code = hamming($data); # Encode $data
$data = unhamming($code); # Decode and fix errors ($data,$errors) = unhamming($code); # + return error count
This is an Error Correction Code module, implementing Hamming encoding (8 bits data, 4 bits Hamming - ie increases data size by 50%). Data can be encoded so that single bit errors within a byte are auto-corrected.
This may be useful as a precaution before storing or sending data where single bit errors are expected.
Hamming encoding was invented by Richard Hamming, Bell Labs, during 1948.
EXPORT SUBROUTINES
hamming (SCALAR)
Returns the Hamming code from the provided input data.
unhamming (SCALAR)
Returns the original data from the provided Hamming code. Single bit errors are auto corrected.
unhamming_err (SCALAR)
Returns the original data from the provided Hamming code, and a number counting the number of bytes that were corrected. Single bit errors are auto corrected.
OTHER SUBROUTINES
Algorithm::Hamming::Perl::hamming_faster ()
This is an optional subroutine that will speed Hamming encoding if it is run once at the start of the program. It does this by using a larger (hash) cache of preprocessed results. The disadvantage is that it uses more memory, and can add several seconds to invocation time. Only use this if you are encoding more than 1 Mb of data.
Download (0.007MB)
Added: 2007-05-16 License: Perl Artistic License Price:
894 downloads
Time::Skew 0.1
Time::Skew is a Perl module that computes local clock skew with respect to a remote clock. more>>
Time::Skew is a Perl module that computes local clock skew with respect to a remote clock.
SYNOPISI
use Time::Skew
# Init Convex Hull and timing data
my $hull=[];
my $result={};
# Iterate data point introduction
Time::Skew::convexhull($result,$datapoint,$hull);
This module supports the computation of the skew between two clocks: the (relative) skew is the speed with which two clocks diverge. For instance, if yesterday two clocks, at the same time, showed respectively 10:00 and 10:05, while today when the former shows 10:00 the latter shows 10:04, we say that their relative skew is 1 minute/24 hours, roughly 7E-4.
The module contains one single subroutine, which accepts as input a pair of timestamps, associated to a message from host A to host B: the timestamps correspond to the time when the message was sent, and to the time when message is received. Each timestamp reflects the value of the local clock where the operation takes place: the clock of host A for the send, the clock of B for the receive.
Please note that the module does _not_ contain any message exchange facility, but only the mathematics needed to perform the skew approximation, once timestamps are known.
The subroutine takes as argument:
a reference to a hash where values related to the timing of the network path from A to B;
a 2-elems array (a data point in the sequel) containing the timestamp of the receive event, and the differece between the send timestamp and the receive timestamp for one message;
a stack containing some data points, those that form the convex hull.
The usage is very simple, and is illustrated by the following example:
#!/usr/bin/perl -w
use strict;
use Time::Skew;
# Initialize data
my $hull=[];
my $result={};
while ( 1 ) {
# Exchange message and acquire a new data point
my $datapoint = acquire();
# Call the convexhull subroutine
Time::Skew::convexhull($result,$datapoint,$hull);
# After first message some results are still undefined
( defined $result->{skewjitter} ) || next;
# here you can use the results
};
}
The data returned in the "result" hash is the following:
result->{skew} the clock skew;
result->{skewjitter} the variance of the skew estimate, used to estimate convergence;
result->{jitter} difference between the current delay and the previous delay;
result->{delay} the communication delay, decremented by a constant (yet unknown) value, used to compute communication jitter;
result->{elems} the number of data points in the convex hull;
result->{select} the index of the data point in the convex hull used to compute the skew;
result->{itimestamp} the timestamp, first element in the data point just passed to the subroutine;
result->{delta} the timestamp difference, second element in the data point just passed to the subroutine;
The data returned in the "hull" stack is a series of data points, selected from those passed to successive calls of the subroutine. The number of data points in the "hull" stack usually does not exceed 20 units.
The algorithm is very fast: each call consists in scanning at most all data points in the "hull" stack, performing simple arithmetic operations for each element.
The algorithm must be fed with a sequence of data points before returning significant results. The accuracy of the estimate keeps growing while new data points are passed to the subroutine. A rough rule of thumb to evaluate estimate accuracy is to observe the skew jitter, and assume it corresponds to the skew estimate accuracy. Paths with quite regular communication delay (small jitter) converge faster.
<<lessSYNOPISI
use Time::Skew
# Init Convex Hull and timing data
my $hull=[];
my $result={};
# Iterate data point introduction
Time::Skew::convexhull($result,$datapoint,$hull);
This module supports the computation of the skew between two clocks: the (relative) skew is the speed with which two clocks diverge. For instance, if yesterday two clocks, at the same time, showed respectively 10:00 and 10:05, while today when the former shows 10:00 the latter shows 10:04, we say that their relative skew is 1 minute/24 hours, roughly 7E-4.
The module contains one single subroutine, which accepts as input a pair of timestamps, associated to a message from host A to host B: the timestamps correspond to the time when the message was sent, and to the time when message is received. Each timestamp reflects the value of the local clock where the operation takes place: the clock of host A for the send, the clock of B for the receive.
Please note that the module does _not_ contain any message exchange facility, but only the mathematics needed to perform the skew approximation, once timestamps are known.
The subroutine takes as argument:
a reference to a hash where values related to the timing of the network path from A to B;
a 2-elems array (a data point in the sequel) containing the timestamp of the receive event, and the differece between the send timestamp and the receive timestamp for one message;
a stack containing some data points, those that form the convex hull.
The usage is very simple, and is illustrated by the following example:
#!/usr/bin/perl -w
use strict;
use Time::Skew;
# Initialize data
my $hull=[];
my $result={};
while ( 1 ) {
# Exchange message and acquire a new data point
my $datapoint = acquire();
# Call the convexhull subroutine
Time::Skew::convexhull($result,$datapoint,$hull);
# After first message some results are still undefined
( defined $result->{skewjitter} ) || next;
# here you can use the results
};
}
The data returned in the "result" hash is the following:
result->{skew} the clock skew;
result->{skewjitter} the variance of the skew estimate, used to estimate convergence;
result->{jitter} difference between the current delay and the previous delay;
result->{delay} the communication delay, decremented by a constant (yet unknown) value, used to compute communication jitter;
result->{elems} the number of data points in the convex hull;
result->{select} the index of the data point in the convex hull used to compute the skew;
result->{itimestamp} the timestamp, first element in the data point just passed to the subroutine;
result->{delta} the timestamp difference, second element in the data point just passed to the subroutine;
The data returned in the "hull" stack is a series of data points, selected from those passed to successive calls of the subroutine. The number of data points in the "hull" stack usually does not exceed 20 units.
The algorithm is very fast: each call consists in scanning at most all data points in the "hull" stack, performing simple arithmetic operations for each element.
The algorithm must be fed with a sequence of data points before returning significant results. The accuracy of the estimate keeps growing while new data points are passed to the subroutine. A rough rule of thumb to evaluate estimate accuracy is to observe the skew jitter, and assume it corresponds to the skew estimate accuracy. Paths with quite regular communication delay (small jitter) converge faster.
Download (0.044MB)
Added: 2007-04-10 License: Perl Artistic License Price:
927 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 subroutine 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