Builder/Parser/Quick.pm

filter: Statementstmt 56.2% 18 / 32 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 47.0% 24 / 51 SCAR 25.4
CC
6
Cov
43%
create_parser
12.0
__ANON__
12.0
__ANON__
6.0
CRAP 12.7
« Builder/Parser/generic.pm ↑ Summary Builder/Parser/Dispatch.pm »
1 package DateTime::Format::Builder::Parser::Quick;
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.82';
7  
8 24 ▶use vars qw( %dispatch_data );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use Params::Validate qw( SCALAR OBJECT CODEREF validate );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 24 ▶use parent qw( DateTime::Format::Builder::Parser );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 __PACKAGE__->valid_params(
15 Quick => {
16 type => SCALAR | OBJECT,
17 callbacks => {
18 good_classname => sub {
19 0 ▶ ( ref $_[0] ) or ( $_[0] =~ /^\w+[:'\w+]*\w+/ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or $_[0] =~ /^\w+[:'\w+]*\w+/ 0 0 0
20 },
21 }
22 },
23 24 method => {
24 optional => 1,
25 type => SCALAR | CODEREF,
26 },
27 );
28  
29 sub create_parser {
30 0 ▶ my ( $self, %args ) = @_;
Subroutine create_parser: not called CC=3 SCAR=24.8
Pod documented
31 0 my $class = $args{Quick};
32 0 my $method = $args{method};
33 0 ▶ $method = 'parse_datetime' unless defined $method;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 0 0
34 0 eval "use $class";
35 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
36  
37 return sub {
38 0 ▶ my ( $self, $date ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
39 0 ▶ return unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 0 0
40 0 my $rv = eval { $class->$method($date) };
41 0 ▶ return $rv if defined $rv;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rv 0 0 0
42 0 return;
43 0 };
44 }
45  
46 24 1;
47  
48 # ABSTRACT: Use another formatter, simply
49  
50 __END__
51  
52 =pod
53  
54 =encoding UTF-8
55  
56 =head1 NAME
57  
58 DateTime::Format::Builder::Parser::Quick - Use another formatter, simply
59  
60 =head1 VERSION
61  
62 version 0.82
63  
64 =head1 SYNOPSIS
65  
66 use DateTime::Format::Builder (
67 parsers => { parse_datetime => [
68 { Quick => 'DateTime::Format::HTTP' },
69 { Quick => 'DateTime::Format::Mail' },
70 { Quick => 'DateTime::Format::IBeat' },
71 ]});
72  
73 is the same as:
74  
75 use DateTime::Format::HTTP;
76 use DateTime::Format::Mail;
77 use DateTime::Format::IBeat;
78  
79 use DateTime::Format::Builder (
80 parsers => { parse_datetime => [
81 sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } },
82 sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } },
83 sub { eval { DateTime::Format::IBeat->parse_datetime( $_[1] ) } },
84 ]});
85  
86 (These two pieces of code can both be found in the test
87 suite; one as F<quick.t>, the other as F<fall.t>.)
88  
89 =head1 DESCRIPTION
90  
91 C<Quick> adds a parser that allows some shortcuts when
92 writing fairly standard and mundane calls to other
93 formatting modules.
94  
95 =head1 SPECIFICATION
96  
97 C<Quick> has two keys, one optional.
98  
99 The C<Quick> keyword should have an argument of either an
100 object or a class name. If it's a class name then the class
101 is C<use>d.
102  
103 The C<method> keyword is optional with a default of
104 C<parse_datetime>. It's either name of the method to invoke
105 on the object, or a reference to a piece of code.
106  
107 In any case, the resultant code ends up looking like:
108  
109 my $rv = $Quick->$method( $date );
110  
111 =head1 SEE ALSO
112  
113 C<datetime@perl.org> mailing list.
114  
115 http://datetime.perl.org/
116  
117 L<perl>, L<DateTime>,
118 L<DateTime::Format::Builder>
119  
120 =head1 SUPPORT
121  
122 Bugs may be submitted at L<http://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-Builder> or via email to L<bug-datetime-format-builder@rt.cpan.org|mailto:bug-datetime-format-builder@rt.cpan.org>.
123  
124 I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
125  
126 =head1 SOURCE
127  
128 The source code repository for DateTime-Format-Builder can be found at L<https://github.com/houseabsolute/DateTime-Format-Builder>.
129  
130 =head1 AUTHORS
131  
132 =over 4
133  
134 =item *
135  
136 Dave Rolsky <autarch@urth.org>
137  
138 =item *
139  
140 Iain Truskett
141  
142 =back
143  
144 =head1 COPYRIGHT AND LICENSE
145  
146 This software is Copyright (c) 2019 by Dave Rolsky.
147  
148 This is free software, licensed under:
149  
150 The Artistic License 2.0 (GPL Compatible)
151  
152 The full text of the license can be found in the
153 F<LICENSE> file included with this distribution.
154  
155 =cut
« Builder/Parser/generic.pm ↑ Summary Builder/Parser/Dispatch.pm »