| 1 | package DateTime::Format::Builder::Parser::generic; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 24 | our $VERSION = '0.83'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use Params::Validate qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | validate SCALAR CODEREF UNDEF | ||||||||||||||||||||||||||||
| 11 | 24 | ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 65 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 65 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 65 | bless {@_}, $class; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 65 | ▶ | sub generic_parser { | ||||||||||||||||||||||||||
|
Subroutine
generic_parser: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 65 | my $class = shift; | |||||||||||||||||||||||||||
| 20 | my %args = validate( | ||||||||||||||||||||||||||||
| 21 | @_, | ||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||
| 23 | ( | ||||||||||||||||||||||||||||
| 24 | 65 | map { $_ => { type => CODEREF, optional => 1 } } | |||||||||||||||||||||||||||
| 25 | qw( | ||||||||||||||||||||||||||||
| 26 | on_match on_fail preprocess postprocess | ||||||||||||||||||||||||||||
| 27 | ) | ||||||||||||||||||||||||||||
| 28 | ), | ||||||||||||||||||||||||||||
| 29 | label => { type => SCALAR | UNDEF, optional => 1 }, | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | 65 | my $label = $args{label}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | my $callback | ||||||||||||||||||||||||||||
| 35 | 65 | ▶ | = ( exists $args{on_match} or exists $args{on_fail} ) ? 1 : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args{"on_match"} or exists $args{"on_fail"}
MC/DC50%1/2
exists $args{"on_match"} or exists $args{"on_fail"}
exists $args{"on_match"}
exists $args{"on_fail"}
Truth table66%2/3
A or B
A= exists $args{"on_match"}B= exists $args{"on_fail"}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 84 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=15 SCAR=27.6
| |||||||||||||||||||||||||||||
| 38 | 84 | my ( $self, $date, $p, @args ) = @_; | |||||||||||||||||||||||||||
| 39 | 84 | ▶ | return unless defined $date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 84 | my %p; | |||||||||||||||||||||||||||
| 41 | 84 | ▶ | %p = %$p if $p; # Look! A Copy! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 84 | ▶ | my %param = ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | self => $self, | ||||||||||||||||||||||||||||
| 45 | ( defined $label ? ( label => $label ) : () ), | ||||||||||||||||||||||||||||
| 46 | ( @args ? ( args => \@args ) : () ), | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Preprocess - can modify $date and fill %p | ||||||||||||||||||||||||||||
| 50 | 84 | ▶ | if ( $args{preprocess} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | $date = $args{preprocess} | ||||||||||||||||||||||||||||
| 52 | 8 | ->( input => $date, parsed => \%p, %param ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 84 | ▶ | my $rv = $class->do_match( $date, @args ) if $class->can('do_match'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Funky callback thing | ||||||||||||||||||||||||||||
| 58 | 84 | ▶ | if ($callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | my $type = defined $rv ? "on_match" : "on_fail"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 6 | ▶ | $args{$type}->( input => $date, %param ) if $args{$type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 84 | ▶ | return unless defined $rv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 44 | my $dt; | |||||||||||||||||||||||||||
| 65 | 44 | ▶ | $dt = $class->post_match( $date, $rv, \%p ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | if $class->can('post_match'); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Allow post processing. Return undef if regarded as failure | ||||||||||||||||||||||||||||
| 69 | 44 | ▶ | if ( $args{postprocess} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 10 | my $rv = $args{postprocess}->( | |||||||||||||||||||||||||||
| 71 | parsed => \%p, | ||||||||||||||||||||||||||||
| 72 | input => $date, | ||||||||||||||||||||||||||||
| 73 | post => $dt, | ||||||||||||||||||||||||||||
| 74 | %param, | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | 10 | ▶ | return unless $rv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # A successful match! | ||||||||||||||||||||||||||||
| 80 | 44 | ▶ | $dt = $class->make( $date, $dt, \%p ) if $class->can('make'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 44 | return $dt; | |||||||||||||||||||||||||||
| 82 | 65 | }; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 24 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 24 | for (qw( valid_params params )) { | |||||||||||||||||||||||||||
| 88 | 48 | *$_ = *{"DateTime::Format::Builder::Parser::$_"}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 24 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # ABSTRACT: Useful routines | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||