Main > Programming > Libraries >

Sub::PatMat 0.01

Sub::PatMat 0.01

Sponsored Links

Sub::PatMat 0.01 Ranking & Summary

RankingClick at the star to rank
Ranking Level
User Review: 0 (0 times)
File size: 0.014 MB
Platform: Any Platform
License: Perl Artistic License
Price:
Downloads: 815
Date added: 2007-08-07
Publisher: Anton Berezin

Sub::PatMat 0.01 description

Sub::PatMat can call a version of subroutine depending on its arguments.
SYNOPSIS
use Sub::PatMat;
# basics:
sub fact : when($_[0] <= 1) { 1 }
sub fact { my ($n) = @_; $n*fact($n-1) }
print fact(6);
# referring to things other than @_:
sub mysort : when($a < $b) { -1 }
sub mysort : when($a == $b) { 0 }
sub mysort : when($a > $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

Sub::PatMat 0.01 Screenshot

Advertisements

Sub::PatMat 0.01 Keywords

Bookmark Sub::PatMat 0.01

Hyperlink code:
Link for forum:

Sub::PatMat 0.01 Copyright

WareSeeker periodically updates pricing and software information of Sub::PatMat 0.01 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of Sub::PatMat 0.01 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed

Allok Video Splitter 2.2.0 Review:

Name (Required)
Email(Required)
Captcha
Featured Software

Want to place your software product here?
Please contact us for consideration.

Contact WareSeeker.com
Related Software
B::XPath class can search Perl optrees with XPath syntax. Free Download
Sub::DeferredPartial is a deferred evaluation / partial application. Free Download
Quantum::Random is an optical quantum random number generator front-end. Free Download
Sub::ArgShortcut is a Perl module with writing functions that use default arguments. Free Download
Sub::Timebound is a Perl extension for timebound computations. Free Download
Amarok XM Tuner is a script that allows playing of xmonline channels through Amarok. Free Download
Be::Attribute is a Perl module to get and set MIME file attributes. Free Download
Asterisk::FastAGI is a Perl module for FastAGI handling. Free Download