sub
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 831
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
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
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
Sub::Assert 1.22
Sub::Assert - Design-by-contract like pre- and postconditions, etc. more>>
Sub::Assert - Design-by-contract like pre- and postconditions, etc.
SYNOPSIS
use Sub::Assert;
sub squareroot {
my $x = shift;
return $x**0.5;
}
assert
pre => $PARAM[0] >= 1, # for the sake of simplicity
post => $VOID or $RETURN squareroot,
context => novoid,
action => carp;
print squareroot(2), "n"; # prints 1.41421 and so on
print squareroot(-1), "n"; # warns
# "Precondition 1 for main::squareroot failed."
squareroot(2); # warns
# "main::squareroot called in void context."
sub faultysqrt {
my $x = shift;
return $x**2;
}
assert
pre => $PARAM[0] >= 1, # for the sake of simplicity
post => $RETURN faultysqrt;
print faultysqrt(2), "n"; # dies with
# "Postcondition 1 for main::squareroot failed."
<<lessSYNOPSIS
use Sub::Assert;
sub squareroot {
my $x = shift;
return $x**0.5;
}
assert
pre => $PARAM[0] >= 1, # for the sake of simplicity
post => $VOID or $RETURN squareroot,
context => novoid,
action => carp;
print squareroot(2), "n"; # prints 1.41421 and so on
print squareroot(-1), "n"; # warns
# "Precondition 1 for main::squareroot failed."
squareroot(2); # warns
# "main::squareroot called in void context."
sub faultysqrt {
my $x = shift;
return $x**2;
}
assert
pre => $PARAM[0] >= 1, # for the sake of simplicity
post => $RETURN faultysqrt;
print faultysqrt(2), "n"; # dies with
# "Postcondition 1 for main::squareroot failed."
Download (0.006MB)
Added: 2007-05-03 License: Perl Artistic License Price:
906 downloads
Sub::Quotelike 0.03
Sub::Quotelike is a Perl module that allows to define quotelike functions. more>>
Sub::Quotelike is a Perl module that allows to define quotelike functions.
SYNOPSIS
use Sub::Quotelike;
sub myq () {
my $s = shift;
# Do something with $s...
return $s;
}
sub myqq (") {
my $s = shift;
# Do something with $s...
return $s;
}
print myq/abc def/;
print myqq{abc $def @ghin};
no Sub::Quotelike; # disallows quotelike functions
# in the remaining code
This module allows to define quotelike functions, that mimic the syntax of the builtin operators q(), qq(), qw(), etc.
To define a quotelike function that interpolates quoted text, use the new (") prototype. For non-interpolating functions, use (). Thats all.
To be polite with some indenters and syntax highlighters, the prototypes () and ("") are accepted as synonyms for () and ("").
<<lessSYNOPSIS
use Sub::Quotelike;
sub myq () {
my $s = shift;
# Do something with $s...
return $s;
}
sub myqq (") {
my $s = shift;
# Do something with $s...
return $s;
}
print myq/abc def/;
print myqq{abc $def @ghin};
no Sub::Quotelike; # disallows quotelike functions
# in the remaining code
This module allows to define quotelike functions, that mimic the syntax of the builtin operators q(), qq(), qw(), etc.
To define a quotelike function that interpolates quoted text, use the new (") prototype. For non-interpolating functions, use (). Thats all.
To be polite with some indenters and syntax highlighters, the prototypes () and ("") are accepted as synonyms for () and ("").
Download (0.004MB)
Added: 2007-05-08 License: Perl Artistic License Price:
900 downloads
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::Exporter 0.970
Sub::Exporter is a sophisticated exporter for custom-built routines. more>>
Sub::Exporter is a sophisticated exporter for custom-built routines.
SYNOPSIS
Sub::Exporter must be used in two places. First, in an exporting module:
# in the exporting module:
package Text::Tweaker;
use Sub::Exporter -setup => {
exports => [
qw(squish titlecase) # always works the same way
reformat => &build_reformatter, # generator to build exported function
trim => &build_trimmer,
indent => &build_indenter,
],
collectors => [ defaults ],
};
Then, in an importing module:
# in the importing module:
use Text::Tweaker
squish,
indent => { margin => 5 },
reformat => { width => 79, justify => full, -as => prettify_text },
defaults => { eol => CRLF };
With this setup, the importing module ends up with three routines: squish, indent, and prettify_text. The latter two have been built to the specifications of the importer -- they are not just copies of the code in the exporting package.
<<lessSYNOPSIS
Sub::Exporter must be used in two places. First, in an exporting module:
# in the exporting module:
package Text::Tweaker;
use Sub::Exporter -setup => {
exports => [
qw(squish titlecase) # always works the same way
reformat => &build_reformatter, # generator to build exported function
trim => &build_trimmer,
indent => &build_indenter,
],
collectors => [ defaults ],
};
Then, in an importing module:
# in the importing module:
use Text::Tweaker
squish,
indent => { margin => 5 },
reformat => { width => 79, justify => full, -as => prettify_text },
defaults => { eol => CRLF };
With this setup, the importing module ends up with three routines: squish, indent, and prettify_text. The latter two have been built to the specifications of the importer -- they are not just copies of the code in the exporting package.
Download (0.034MB)
Added: 2006-10-20 License: Perl Artistic License Price:
1100 downloads
Sub::ArgShortcut 1.01
Sub::ArgShortcut is a Perl module with writing functions that use default arguments. more>>
Sub::ArgShortcut is a Perl module with writing functions that use default arguments.
SYNOPSIS
use Sub::ArgShortcut::Attr;
sub mychomp :ArgShortcut { chomp @_ }
while ( ) {
# make a chomped copy of $_ without modifying it
my $chomped_line = mychomp;
# or, modify $_ in place
mychomp;
# ...
}
This module encapsulates the logic required for functions that assume $_ as their argument when called with an empty argument list, and which modify their arguments in void context but return modified copies in any other context. You only need to write code which modifies the elements of @_ in-place.
argshortcut(&)
This function takes a code reference as input, wraps a function around it and returns a reference to that function. The code that is passed in should modify the values in @_ in whatever fashion desired. The function from the synopsis could therefore also be written like this:
use Sub::ArgShortcut;
my $mychomp = argshortcut { chomp @_ };
This function is exported by default.
Sub::ArgShortcut::Attr and :ArgShortcut - The attribute interface
Instead of using argshortcut to wrap a code reference, you can use an Attribute::Handler-based interface to add Sub::ArgShortcut functionality to regular subs. Simply use Sub::Shortcut::Attr instead of Sub::Shortcut, then request its behaviour using the :ArgShortcut attribute on functions:
sub mychomp :ArgShortcut { chomp @_ }
my $mychomp = sub :ArgShortcut { chomp @_ };
<<lessSYNOPSIS
use Sub::ArgShortcut::Attr;
sub mychomp :ArgShortcut { chomp @_ }
while ( ) {
# make a chomped copy of $_ without modifying it
my $chomped_line = mychomp;
# or, modify $_ in place
mychomp;
# ...
}
This module encapsulates the logic required for functions that assume $_ as their argument when called with an empty argument list, and which modify their arguments in void context but return modified copies in any other context. You only need to write code which modifies the elements of @_ in-place.
argshortcut(&)
This function takes a code reference as input, wraps a function around it and returns a reference to that function. The code that is passed in should modify the values in @_ in whatever fashion desired. The function from the synopsis could therefore also be written like this:
use Sub::ArgShortcut;
my $mychomp = argshortcut { chomp @_ };
This function is exported by default.
Sub::ArgShortcut::Attr and :ArgShortcut - The attribute interface
Instead of using argshortcut to wrap a code reference, you can use an Attribute::Handler-based interface to add Sub::ArgShortcut functionality to regular subs. Simply use Sub::Shortcut::Attr instead of Sub::Shortcut, then request its behaviour using the :ArgShortcut attribute on functions:
sub mychomp :ArgShortcut { chomp @_ }
my $mychomp = sub :ArgShortcut { chomp @_ };
Download (0.005MB)
Added: 2007-05-03 License: Perl Artistic License Price:
904 downloads
Sub Ether Release II
Sub Ether is a system that includes software to network computers together. more>>
Sub Ether is a system that includes software to network computers together over the Internet so that applications can share resources.
Sub Ether is basically a grid computer over the Internet using volunteers spare CPU and disk resources.
An example application written for Sub Ether is sedistcc. It allows you to use distcc to use compilers on machines running elsewhere on the Sub Ether network.
Quick Install for Unix:
If you untar/zip SubEtherInstallRelease-*.tgz youll get a few directories of source,
and some scripts:
1) buildse.sh builds the source code on some number of unix machines
2) installse.sh does a simple copying/updating of files to /usr/local/subether
3) setupsetorunandstart.sh will update /etc/inittab and make a file in /etc/xinetd.d
If you are running a flavor of unix that the script does not recognize it wont update
anything. You have to be root for this to work, and you have to have the balls to run it.
Run buildse.sh
Ive tested it on some number of redhats and freebsd and AIX. I also have a build
for windows, but it doesnt include the compiler program, so it would be good for socket bouncing only at the moment, until I finish some more applications (like sefile)
If all goes well, youll get a clean build. Dont worry about seeing it the build was
clean, the install script will complain if somethings missing.
If you can log in as some user that has access to /usr/local oot and dont have a
problem with putting stuff in /usr/local/subether, then you can run installse.sh as is.
Run installse.sh
*** OR *** if you want to install it into another directory (say because you dont
have root on the machine) you can specify where to put it by passing the directory as
a parameter:
Run installse.sh /path/to/existing/dir/subether
The /path/to/existing/dir has to exist, the script will create subether. You dont
have to call it that, but why wouldnt you.
Then, if youre all excited that things are going really well in your life, and
youre feeling really ballsy, run setupsetorunandstart.sh
Note, as of release 2, this doesnt exist yet, but it will.
Run setupsetorunandstart.sh
This is the finiky bit so you might want to do this by hand.
You have to be root for this to work anyway.
It will check to see if you have distcc set up on the machine, and if so,
create a file /etc/xinetd.d/distcc.
It will also add a few lines to the bottom of your /etc/inittab, and back up
the old one. And also add a line to /etc/services for distcc
Then it will kick xinetd, and telinit q. And if all goes well, youll be a
happy member of the Sub Ether network already sharing your spare cpu for use by other people using subether and distcc.
If you want to use distcc to do your compiles with the help of the Sub Ether
networked computers, you have a few more steps of setup that are covered in the
HOWTO-install_sedistccd file.
<<lessSub Ether is basically a grid computer over the Internet using volunteers spare CPU and disk resources.
An example application written for Sub Ether is sedistcc. It allows you to use distcc to use compilers on machines running elsewhere on the Sub Ether network.
Quick Install for Unix:
If you untar/zip SubEtherInstallRelease-*.tgz youll get a few directories of source,
and some scripts:
1) buildse.sh builds the source code on some number of unix machines
2) installse.sh does a simple copying/updating of files to /usr/local/subether
3) setupsetorunandstart.sh will update /etc/inittab and make a file in /etc/xinetd.d
If you are running a flavor of unix that the script does not recognize it wont update
anything. You have to be root for this to work, and you have to have the balls to run it.
Run buildse.sh
Ive tested it on some number of redhats and freebsd and AIX. I also have a build
for windows, but it doesnt include the compiler program, so it would be good for socket bouncing only at the moment, until I finish some more applications (like sefile)
If all goes well, youll get a clean build. Dont worry about seeing it the build was
clean, the install script will complain if somethings missing.
If you can log in as some user that has access to /usr/local oot and dont have a
problem with putting stuff in /usr/local/subether, then you can run installse.sh as is.
Run installse.sh
*** OR *** if you want to install it into another directory (say because you dont
have root on the machine) you can specify where to put it by passing the directory as
a parameter:
Run installse.sh /path/to/existing/dir/subether
The /path/to/existing/dir has to exist, the script will create subether. You dont
have to call it that, but why wouldnt you.
Then, if youre all excited that things are going really well in your life, and
youre feeling really ballsy, run setupsetorunandstart.sh
Note, as of release 2, this doesnt exist yet, but it will.
Run setupsetorunandstart.sh
This is the finiky bit so you might want to do this by hand.
You have to be root for this to work anyway.
It will check to see if you have distcc set up on the machine, and if so,
create a file /etc/xinetd.d/distcc.
It will also add a few lines to the bottom of your /etc/inittab, and back up
the old one. And also add a line to /etc/services for distcc
Then it will kick xinetd, and telinit q. And if all goes well, youll be a
happy member of the Sub Ether network already sharing your spare cpu for use by other people using subether and distcc.
If you want to use distcc to do your compiles with the help of the Sub Ether
networked computers, you have a few more steps of setup that are covered in the
HOWTO-install_sedistccd file.
Download (0.13MB)
Added: 2006-05-25 License: GPL (GNU General Public License) Price:
1248 downloads
GSubEdit 0.4pre1
GSubEdit, or GNOME Subtitle Editor, is a tool for editing and converting DivX ;-) subtitles. more>>
GSubEdit, or GNOME Subtitle Editor, is a tool for editing and converting DivX ;-) subtitles. It currently features read/write of SubRip (.srt) and MicroDVD (.sub) subtitles.
Framerate conversion and frame displacement (Increase/decrease all frames by a given offset) is also supported.
Main features:
- Open and saving of SubRip (.srt) and MicroDVD (.sub)
- Framerate conversion (.sub and .srt)
- Frame displacement. Used if the frames is shown to early or to late. (.sub and .srt)
- Removing of the text used for hearing impaired. (.sub and .srt)
- Split file into two parts
- Join two files into one
- Editing of text, start- and end- frame/time (.sub and .srt)
- DragnDrop, search and replace and support for i18n (only Swedish is currently available)
- Spellcheck
<<lessFramerate conversion and frame displacement (Increase/decrease all frames by a given offset) is also supported.
Main features:
- Open and saving of SubRip (.srt) and MicroDVD (.sub)
- Framerate conversion (.sub and .srt)
- Frame displacement. Used if the frames is shown to early or to late. (.sub and .srt)
- Removing of the text used for hearing impaired. (.sub and .srt)
- Split file into two parts
- Join two files into one
- Editing of text, start- and end- frame/time (.sub and .srt)
- DragnDrop, search and replace and support for i18n (only Swedish is currently available)
- Spellcheck
Download (0.078MB)
Added: 2005-08-17 License: GPL (GNU General Public License) Price:
1533 downloads
IPC::PubSub 0.22
IPC::PubSub is Perl module for Interprocess Publish/Subscribe channels. more>>
IPC::PubSub is Perl module for Interprocess Publish/Subscribe channels.
SYNOPSIS
# A new message bus with the DBM::Deep backend
# (Other possible backends include Memcached and PlainHash)
my $bus = IPC::PubSub->new(DBM_Deep => /tmp/pubsub.db);
# A channel is any arbitrary string
my $channel = #perl6;
# Register a new publisher (you can publish to multiple channels)
my $pub = $bus->new_publisher("#perl6", "#moose");
# Publish a message (may be a complex object) to those channels
$pub->msg("This is a message");
# Register a new subscriber (you can subscribe to multiple channels)
my $sub = $bus->new_subscriber("#moose");
# Publish an object to channels
$pub->msg("This is another message");
# Set all subsequent messages from this publisher to expire in 30 seconds
$pub->expiry(30);
$pub->msg("This message will go away in 30 seconds");
# Simple get: Returns the messages sent since the previous get,
# but only for the first channel.
my @msgs = $sub->get;
# Simple get, with an explicit channel key (must be among the ones
# it initially subscribed to)
my @moose_msgs = $sub->get("#moose");
# Complex get: Returns a hash reference from channels to array
# references of [timestamp, message].
my $hash_ref = $sub->get_all;
# Changing the list of channels we subscribe to
$sub->subscribe(some-other-channel);
$sub->unsubscribe(some-other-channel);
# Changing the list of channels we publish to
$pub->publish(some-other-channel);
$pub->unpublish(some-other-channel);
# Listing and checking if we are in a channel
my @sub_channels = $sub->channels;
my @pub_channels = $pub->channels;
print "Sub is in #moose" if $sub->channels->{#moose};
print "Pub is in #moose" if $pub->channels->{#moose};
# Raw cache manipulation APIs (not advised; use ->modify instead)
$bus->lock(channel);
$bus->unlock(channel);
my @timed_msgs = $bus->fetch(key1, key2, key3);
$bus->store(key, value, time, 30);
# Atomic updating of cache content; $_ is stored back on the
# end of the callback.
my $rv = $bus->modify(key => sub { delete $_->{foo} });
# Shorthand for $bus->modify(key => sub { $_ = val });
$bus->modify(key => val);
# Shorthand for $bus->modify(key => sub { $_ });
$bus->modify(key);
This module provides a simple API for publishing messages to channels and for subscribing to them.
When a message is published on a channel, all subscribers currently in that channel will get it on their next get or get_all call.
Currently, it offers three backends: DBM_Deep for on-disk storage, Memcached for possibly multi-host storage, and PlainHash for single-process storage.
Please see the tests in t/ for this distribution, as well as "SYNOPSIS" above, for some usage examples; detailed documentation is not yet available.
<<lessSYNOPSIS
# A new message bus with the DBM::Deep backend
# (Other possible backends include Memcached and PlainHash)
my $bus = IPC::PubSub->new(DBM_Deep => /tmp/pubsub.db);
# A channel is any arbitrary string
my $channel = #perl6;
# Register a new publisher (you can publish to multiple channels)
my $pub = $bus->new_publisher("#perl6", "#moose");
# Publish a message (may be a complex object) to those channels
$pub->msg("This is a message");
# Register a new subscriber (you can subscribe to multiple channels)
my $sub = $bus->new_subscriber("#moose");
# Publish an object to channels
$pub->msg("This is another message");
# Set all subsequent messages from this publisher to expire in 30 seconds
$pub->expiry(30);
$pub->msg("This message will go away in 30 seconds");
# Simple get: Returns the messages sent since the previous get,
# but only for the first channel.
my @msgs = $sub->get;
# Simple get, with an explicit channel key (must be among the ones
# it initially subscribed to)
my @moose_msgs = $sub->get("#moose");
# Complex get: Returns a hash reference from channels to array
# references of [timestamp, message].
my $hash_ref = $sub->get_all;
# Changing the list of channels we subscribe to
$sub->subscribe(some-other-channel);
$sub->unsubscribe(some-other-channel);
# Changing the list of channels we publish to
$pub->publish(some-other-channel);
$pub->unpublish(some-other-channel);
# Listing and checking if we are in a channel
my @sub_channels = $sub->channels;
my @pub_channels = $pub->channels;
print "Sub is in #moose" if $sub->channels->{#moose};
print "Pub is in #moose" if $pub->channels->{#moose};
# Raw cache manipulation APIs (not advised; use ->modify instead)
$bus->lock(channel);
$bus->unlock(channel);
my @timed_msgs = $bus->fetch(key1, key2, key3);
$bus->store(key, value, time, 30);
# Atomic updating of cache content; $_ is stored back on the
# end of the callback.
my $rv = $bus->modify(key => sub { delete $_->{foo} });
# Shorthand for $bus->modify(key => sub { $_ = val });
$bus->modify(key => val);
# Shorthand for $bus->modify(key => sub { $_ });
$bus->modify(key);
This module provides a simple API for publishing messages to channels and for subscribing to them.
When a message is published on a channel, all subscribers currently in that channel will get it on their next get or get_all call.
Currently, it offers three backends: DBM_Deep for on-disk storage, Memcached for possibly multi-host storage, and PlainHash for single-process storage.
Please see the tests in t/ for this distribution, as well as "SYNOPSIS" above, for some usage examples; detailed documentation is not yet available.
Download (0.019MB)
Added: 2007-02-14 License: MIT/X Consortium License Price:
983 downloads
Sub::DeferredPartial 0.01
Sub::DeferredPartial is a deferred evaluation / partial application. more>>
Sub::DeferredPartial is a deferred evaluation / partial application.
SYNOPSIS
use Sub::DeferredPartial def;
$S = def sub : P1 P2 P3 { %_=@_; join , @_{qw(P1 P2 P3)} };
print $S->( P1 => 1, P2 => 2, P3 => 3 )->(); # 123
$A = $S->( P3 => 1 ); # partial application
$B = $S->( P3 => 2 );
$C = $A + $B; # deferred evaluation
$D = $C->( P2 => 3 );
$E = $D->( P1 => 4 );
print $E->(); # force evaluation: 863
$F = $E - $D;
$G = $F->( P1 => 0 ) / 2;
print $G->(); # 400
print $G; # ( ( CODE(0x15e3818): P1 => 4, P2 => 3, P3 => 1 + CODE ...
$F->(); # Error: Free parameter : P1
$A->( P3 => 7 ); # Error: Bound parameter: P3
$A->( P4 => 7 ); # Error: Wrong parameter: P4
An instance of this class behaves like a sub (or, more precisely: subroutine reference), but it supports partial application and the evaluation of operators applied to such function objects is deferred too.
That means, evaluation has to be forced explicitly (which makes it easier to add introspection capabilities).
Objects that represent deferred (delayed, suspended) expressions are known as suspensions or thunks in various programming circles. Dont confuse with the same terms in the context of threads!
<<lessSYNOPSIS
use Sub::DeferredPartial def;
$S = def sub : P1 P2 P3 { %_=@_; join , @_{qw(P1 P2 P3)} };
print $S->( P1 => 1, P2 => 2, P3 => 3 )->(); # 123
$A = $S->( P3 => 1 ); # partial application
$B = $S->( P3 => 2 );
$C = $A + $B; # deferred evaluation
$D = $C->( P2 => 3 );
$E = $D->( P1 => 4 );
print $E->(); # force evaluation: 863
$F = $E - $D;
$G = $F->( P1 => 0 ) / 2;
print $G->(); # 400
print $G; # ( ( CODE(0x15e3818): P1 => 4, P2 => 3, P3 => 1 + CODE ...
$F->(); # Error: Free parameter : P1
$A->( P3 => 7 ); # Error: Bound parameter: P3
$A->( P4 => 7 ); # Error: Wrong parameter: P4
An instance of this class behaves like a sub (or, more precisely: subroutine reference), but it supports partial application and the evaluation of operators applied to such function objects is deferred too.
That means, evaluation has to be forced explicitly (which makes it easier to add introspection capabilities).
Objects that represent deferred (delayed, suspended) expressions are known as suspensions or thunks in various programming circles. Dont confuse with the same terms in the context of threads!
Download (0.005MB)
Added: 2007-05-03 License: Perl Artistic License Price:
904 downloads
Sub::Slice::Manual 1.048
Sub::Slice::Manual is a Perl module with user guide for Sub::Slice. more>>
Sub::Slice::Manual is a Perl module with user guide for Sub::Slice.
USING Sub::Slice
Sub::Slice is a way of breaking down a long-running process and maintaining state across a stateless protocol. This allows the client to draw a progress bar or abort the process part-way through.
The mechanism used by Sub::Slice is similar to the session management used on many web user authentication systems. However rather than simply passing an ID back as a token as these systems do, in Sub::Slice a data structure with richer information is passed to the client, allowing the client to make some intelligent decisions rather than blindly maintain state.
Use of Sub::Slice is best explained with a minimal example. Assume that there is a remoting protocol between the client and server such as XML/HTTP. For the sake of brevity, assume that methods called in package Server:: on the client are magically remoted to the server.
The server does two things. The first is to issue a token for the client to use:
#Server
sub create_token {
my $job = new Sub::Slice();
return $job->token;
}
The second is to provide the routine into which the token is passed for each iteration:
sub do_work {
my $token = shift;
my $job = new Sub::Slice(token => $token);
at_start $job sub {
my $files = files_to_process();
#Store some data defining the work to do
$job->store("files", $files);
};
at_stage $job "each_iteration" sub {
#Get some work
my $files = $job->fetch("files");
my $file = shift @$files;
my $was_ok = process_file($file);
#Record we did the work
$job->store("files", $files);
#Check if theres any more work left to do
$job->done() unless(@$files);
};
}
The client somehow gets a token back from the server. It then passes this back to the server for each iteration. It can inspect the token to check if there is any more work left.
#Client
my $token = Server::create_token();
for(1 .. MAX_ITERATIONS) {
Server::do_work($token);
last if $token->{done};
}
<<lessUSING Sub::Slice
Sub::Slice is a way of breaking down a long-running process and maintaining state across a stateless protocol. This allows the client to draw a progress bar or abort the process part-way through.
The mechanism used by Sub::Slice is similar to the session management used on many web user authentication systems. However rather than simply passing an ID back as a token as these systems do, in Sub::Slice a data structure with richer information is passed to the client, allowing the client to make some intelligent decisions rather than blindly maintain state.
Use of Sub::Slice is best explained with a minimal example. Assume that there is a remoting protocol between the client and server such as XML/HTTP. For the sake of brevity, assume that methods called in package Server:: on the client are magically remoted to the server.
The server does two things. The first is to issue a token for the client to use:
#Server
sub create_token {
my $job = new Sub::Slice();
return $job->token;
}
The second is to provide the routine into which the token is passed for each iteration:
sub do_work {
my $token = shift;
my $job = new Sub::Slice(token => $token);
at_start $job sub {
my $files = files_to_process();
#Store some data defining the work to do
$job->store("files", $files);
};
at_stage $job "each_iteration" sub {
#Get some work
my $files = $job->fetch("files");
my $file = shift @$files;
my $was_ok = process_file($file);
#Record we did the work
$job->store("files", $files);
#Check if theres any more work left to do
$job->done() unless(@$files);
};
}
The client somehow gets a token back from the server. It then passes this back to the server for each iteration. It can inspect the token to check if there is any more work left.
#Client
my $token = Server::create_token();
for(1 .. MAX_ITERATIONS) {
Server::do_work($token);
last if $token->{done};
}
Download (0.027MB)
Added: 2006-09-18 License: Perl Artistic License Price:
1132 downloads
Sub::Exporter::Tutorial 0.970
Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter. more>>
Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter.
Whats an Exporter?
When you use a module, first it is required, then its import method is called. The Perl documentation tells us that the following two lines are equivalent:
use Module LIST;
BEGIN { require Module; Module->import(LIST); }
The import method is the modules exporter.
The Basics of Sub::Exporter
Sub::Exporter builds a custom exporter which can then be installed into your module. It builds this method based on configuration passed to its setup_exporter method.
A very basic use case might look like this:
package Addition;
use Sub::Exporter;
Sub::Exporter::setup_exporter({ exports => [ qw(plus) ]});
sub plus { my ($x, $y) = @_; return $x + $y; }
This would mean that when someone used your Addition module, they could have its plus routine imported into their package:
use Addition qw(plus);
my $z = plus(2, 2); # this works, because now plus is in the main package
That syntax to set up the exporter, above, is a little verbose, so for the simple case of just naming some exports, you can write this:
use Sub::Exporter -setup => { exports => [ qw(plus) ] };
...which is the same as the original example -- except that now the exporter is built and installed at compile time. Well, that and you typed less.
Using Export Groups
You can specify whole groups of things that should be exportable together. These are called groups. Exporter calls these tags. To specify groups, you just pass a groups key in your exporter configuration:
package Food;
use Sub::Exporter -setup => {
exports => [ qw(apple banana beef fluff lox rabbit) ],
groups => {
fauna => [ qw(beef lox rabbit) ],
flora => [ qw(apple banana) ],
}
};
Now, to import all that delicious foreign meat, your consumer needs only to write:
use Food qw(:fauna);
use Food qw(-fauna);
Either one of the above is acceptable. A colon is more traditional, but barewords with a leading colon cant be enquoted by a fat arrow. Well see why that matters later on.
Groups can contain other groups. If you include a group name (with the leading dash or colon) in a group definition, it will be expanded recursively when the exporter is called. The exporter will not recurse into the same group twice while expanding groups.
There are two special groups: all and default. The all group is defined by default, and contains all exportable subs. You can redefine it, if you want to export only a subset when all exports are requested. The default group is the set of routines to export when nothing specific is requested. By default, there is no default group.
<<lessWhats an Exporter?
When you use a module, first it is required, then its import method is called. The Perl documentation tells us that the following two lines are equivalent:
use Module LIST;
BEGIN { require Module; Module->import(LIST); }
The import method is the modules exporter.
The Basics of Sub::Exporter
Sub::Exporter builds a custom exporter which can then be installed into your module. It builds this method based on configuration passed to its setup_exporter method.
A very basic use case might look like this:
package Addition;
use Sub::Exporter;
Sub::Exporter::setup_exporter({ exports => [ qw(plus) ]});
sub plus { my ($x, $y) = @_; return $x + $y; }
This would mean that when someone used your Addition module, they could have its plus routine imported into their package:
use Addition qw(plus);
my $z = plus(2, 2); # this works, because now plus is in the main package
That syntax to set up the exporter, above, is a little verbose, so for the simple case of just naming some exports, you can write this:
use Sub::Exporter -setup => { exports => [ qw(plus) ] };
...which is the same as the original example -- except that now the exporter is built and installed at compile time. Well, that and you typed less.
Using Export Groups
You can specify whole groups of things that should be exportable together. These are called groups. Exporter calls these tags. To specify groups, you just pass a groups key in your exporter configuration:
package Food;
use Sub::Exporter -setup => {
exports => [ qw(apple banana beef fluff lox rabbit) ],
groups => {
fauna => [ qw(beef lox rabbit) ],
flora => [ qw(apple banana) ],
}
};
Now, to import all that delicious foreign meat, your consumer needs only to write:
use Food qw(:fauna);
use Food qw(-fauna);
Either one of the above is acceptable. A colon is more traditional, but barewords with a leading colon cant be enquoted by a fat arrow. Well see why that matters later on.
Groups can contain other groups. If you include a group name (with the leading dash or colon) in a group definition, it will be expanded recursively when the exporter is called. The exporter will not recurse into the same group twice while expanding groups.
There are two special groups: all and default. The all group is defined by default, and contains all exportable subs. You can redefine it, if you want to export only a subset when all exports are requested. The default group is the set of routines to export when nothing specific is requested. By default, there is no default group.
Download (0.034MB)
Added: 2006-10-16 License: Perl Artistic License Price:
1104 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
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 sub 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