NAME
Factory::Sub - Generate a factory of subs
VERSION
Version 0.10
SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
my
$factory
= Factory::Sub->new();
$factory
->add(
sub
{
return
'fallback'
});
$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
4;
});
$factory
->(
'hello'
,
'world'
);
# 1
$factory
->(
'hello'
, {
one
=> 1 });
# 2
$factory
->([
qw/h e l l o/
], {
one
=> 1 });
# 3
$factory
->(
'h, e, l, l, o'
,
'world'
, {
one
=> 1 });
# 4
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(
'h, e, l, l, o'
,
'world'
, {
one
=> 1 });
...
$factory
->(
'h, e, l, l, o'
,
'world'
, {
one
=> 1 });
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)