Factory::Sub - Generate a factory of subs
Version 0.04
Quick summary of what the module does.
Perhaps a little code snippet.
use Factory::Sub qw/Str HashRef ArrayRef StrToArray StrToHash HashToArray/; my $factory = Factory::Sub->new(); $factory->add(Str, Str, sub { return 1; }); $factory->add(Str, HashRef, sub { return 2; }); $factory->add(ArrayRef, HashRef, sub { return 3; }); $factory->add(StrToArray->by(', '), StrToHash->by(' '), HashToArray->by('keys'), sub { return $_[1]; }); $factory->('go', 'tell'); # 1 $factory->('all', { your => 'friends' }); # 2 $factory->([qw/t h a t/], { this => 'is' }); # 3 $factory->('t, h, e', 'end', { name => 'day ender' }); # destiny
Instantiate a new Factory::Sub object. This does not accept any argurments.
my $factory = Factory::Sub->new( [Str, Str, sub { return 1 }], [Str, HashRef, sub { return 2 }], [ArrayRef, HashRef, sub { return 3 }] );
Add a new condition to the factory.
$factory->add(StrToArray->by(', '), StrToHash->by(' '), HashToArray->by('keys'), sub { return 4; });
Call the factory. If o matching factory sub is not found for the given params then the code currently croaks with an error.
$factory->call('t, h, e', 'end', { name => 'day ender' }); ... $factory->('t, h, e', 'end', { name => 'day ender' });
LNATION, <email at lnation.org>
<email at lnation.org>
Please report any bugs or feature requests to bug-factory-sub at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Factory-Sub. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-factory-sub at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Factory::Sub
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Factory-Sub
CPAN Ratings
https://cpanratings.perl.org/d/Factory-Sub
Search CPAN
https://metacpan.org/release/Factory-Sub
This software is Copyright (c) 2022 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Factory::Sub, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Factory::Sub
CPAN shell
perl -MCPAN -e shell install Factory::Sub
For more information on module installation, please visit the detailed CPAN module installation guide.