| 1 | package Date::Transform::Closures; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Switch 'Perl6'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Tie::IxHash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | require Exporter; | |||||||||
| 11 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | our @ISA = qw( Exporter ); | |||||||||
| 13 | |||||||||||
| 14 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 15 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 16 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 17 | |||||||||||
| 18 | # This allows declaration use Date::Transform ':all'; | ||||||||||
| 19 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||
| 20 | # will save memory. | ||||||||||
| 21 | 1 | our %EXPORT_TAGS = | |||||||||
| 22 | ( 'all' => [qw( mk_set_filter_input mk_passthru mk_function)] ); | ||||||||||
| 23 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 24 | 1 | our @EXPORT = qw( mk_set_filter_input mk_passthru mk_function ); | |||||||||
| 25 | |||||||||||
| 26 | 1 | our $VERSION = '0.11'; | |||||||||
| 27 | |||||||||||
| 28 | ## SUBROUTINE: mk_set_filter_input | ||||||||||
| 29 | ## Generates a function that sets the key of Tie::IxHash | ||||||||||
| 30 | ## The key of the object is set to the value of the evaluated function. | ||||||||||
| 31 | ## | ||||||||||
| 32 | ## Usage: $fn = mk_set_filter_input( $key, $f); | ||||||||||
| 33 | ## Tie::IxHash_obj->$fn | ||||||||||
| 34 | ## | ||||||||||
| 35 | 6 | ▶ | sub mk_set_filter_input { | ||||||||
|
Subroutine
mk_set_filter_input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | 6 | my $key = shift; | |||||||||
| 38 | 6 | my $function = shift; | |||||||||
| 39 | |||||||||||
| 40 | my $new_function = | ||||||||||
| 41 | |||||||||||
| 42 | 6 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | 6 | my $self = shift; | |||||||||
| 45 | $self->{filter}->{input} | ||||||||||
| 46 | 6 | ->STORE( $key, $self->{filter}->{matches}->$function ); | |||||||||
| 47 | |||||||||||
| 48 | 6 | }; | |||||||||
| 49 | |||||||||||
| 50 | 6 | return $new_function; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | ## SUBROUTINE: mk_passthrough | ||||||||||
| 54 | ## Generates a function that returns the value of the Tie::IxHash | ||||||||||
| 55 | ## The value returned is specified by the passed argument key. | ||||||||||
| 56 | ## * In the anonymous function, $self will be a Tie::IxHash object, | ||||||||||
| 57 | ## Input Object. | ||||||||||
| 58 | ## | ||||||||||
| 59 | ## Usage: $fn = mk_passthru( $key ); | ||||||||||
| 60 | ## Tie::IxHash_obj->$fn | ||||||||||
| 61 | 4 | ▶ | sub mk_passthru { | ||||||||
|
Subroutine
mk_passthru: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 62 | |||||||||||
| 63 | 4 | my $key = shift; | |||||||||
| 64 | 4 | ▶ | carp("No key provided for passthru\n") if ( !defined $key ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 4 | ▶ | my $function = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 67 | |||||||||||
| 68 | 4 | my $self = shift; | |||||||||
| 69 | 4 | my $value = $self->FETCH($key); | |||||||||
| 70 | |||||||||||
| 71 | 4 | return $value; | |||||||||
| 72 | |||||||||||
| 73 | 4 | }; | |||||||||
| 74 | |||||||||||
| 75 | 4 | return $function; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | ## SUBROUTINE: mk_function | ||||||||||
| 79 | ## returns a closure that applies $function to the value(s) | ||||||||||
| 80 | ## of the key(s), @keys | ||||||||||
| 81 | ## | ||||||||||
| 82 | ## usage: mk_function( ref_to_function, Tie::IxHash_keys object ); | ||||||||||
| 83 | ## | ||||||||||
| 84 | 2 | ▶ | sub mk_function { | ||||||||
|
Subroutine
mk_function: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 85 | |||||||||||
| 86 | 2 | my $function = shift; | |||||||||
| 87 | 2 | my @keys = @_; | |||||||||
| 88 | |||||||||||
| 89 | ## print "@keys\n"; | ||||||||||
| 90 | |||||||||||
| 91 | 2 | ▶ | my $new_function = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 92 | |||||||||||
| 93 | 2 | my $matches = shift; | |||||||||
| 94 | 2 | my @inputs = map { $matches->FETCH($_) } @keys; | |||||||||
| 95 | |||||||||||
| 96 | 2 | return &$function(@inputs); | |||||||||
| 97 | |||||||||||
| 98 | 2 | }; | |||||||||
| 99 | |||||||||||
| 100 | 2 | return $new_function; | |||||||||
| 101 | |||||||||||
| 102 | } # END SUBROUTINE: mk_function | ||||||||||
| 103 | |||||||||||
| 104 | 1 | 1; | |||||||||
| 105 | |||||||||||
| 106 | __END__; | ||||||||||