NAME
Factory::Sub - Generate a factory of subs
VERSION
Version 0.04
SYNOPSIS
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
SUBROUTINES/METHODS
new
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
Add a new condition to the factory.
$factory->add(StrToArray->by(', '), StrToHash->by(' '), HashToArray->by('keys'), sub {
return 4;
});
call
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' });
AUTHOR
LNATION, <email at lnation.org>
BUGS
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.
SUPPORT
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)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2022 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)