• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/CPANInternal-159.1/DateTime-Format-Builder-0.81/lib/DateTime/Format/Builder/Parser/
1package DateTime::Format::Builder::Parser::Quick;
2{
3  $DateTime::Format::Builder::Parser::Quick::VERSION = '0.81';
4}
5use strict;
6use warnings;
7use vars qw( %dispatch_data );
8use Params::Validate qw( SCALAR OBJECT CODEREF validate );
9use base qw( DateTime::Format::Builder::Parser );
10
11
12
13__PACKAGE__->valid_params(
14    Quick => {
15        type      => SCALAR | OBJECT,
16        callbacks => {
17            good_classname => sub {
18                ( ref $_[0] ) or ( $_[0] =~ /^\w+[:'\w+]*\w+/ );
19            },
20        }
21    },
22    method => {
23        optional => 1,
24        type     => SCALAR | CODEREF,
25    },
26);
27
28sub create_parser {
29    my ( $self, %args ) = @_;
30    my $class  = $args{Quick};
31    my $method = $args{method};
32    $method = 'parse_datetime' unless defined $method;
33    eval "use $class";
34    die $@ if $@;
35
36    return sub {
37        my ( $self, $date ) = @_;
38        return unless defined $date;
39        my $rv = eval { $class->$method($date) };
40        return $rv if defined $rv;
41        return;
42    };
43}
44
451;
46
47# ABSTRACT: Use another formatter, simply
48
49__END__
50
51=pod
52
53=head1 NAME
54
55DateTime::Format::Builder::Parser::Quick - Use another formatter, simply
56
57=head1 VERSION
58
59version 0.81
60
61=head1 SYNOPSIS
62
63    use DateTime::Format::Builder (
64    parsers => { parse_datetime => [
65        { Quick => 'DateTime::Format::HTTP' },
66        { Quick => 'DateTime::Format::Mail' },
67        { Quick => 'DateTime::Format::IBeat' },
68    ]});
69
70is the same as:
71
72    use DateTime::Format::HTTP;
73    use DateTime::Format::Mail;
74    use DateTime::Format::IBeat;
75
76    use DateTime::Format::Builder (
77    parsers => { parse_datetime => [
78        sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } },
79        sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } },
80        sub { eval { DateTime::Format::IBeat->parse_datetime( $_[1] ) } },
81    ]});
82
83(These two pieces of code can both be found in the test
84suite; one as F<quick.t>, the other as F<fall.t>.)
85
86=head1 DESCRIPTION
87
88C<Quick> adds a parser that allows some shortcuts when
89writing fairly standard and mundane calls to other
90formatting modules.
91
92=head1 SPECIFICATION
93
94C<Quick> has two keys, one optional.
95
96The C<Quick> keyword should have an argument of either an
97object or a class name. If it's a class name then the class
98is C<use>d.
99
100The C<method> keyword is optional with a default of
101C<parse_datetime>. It's either name of the method to invoke
102on the object, or a reference to a piece of code.
103
104In any case, the resultant code ends up looking like:
105
106     my $rv = $Quick->$method( $date );
107
108=head1 SUPPORT
109
110See L<DateTime::Format::Builder> for details.
111
112=head1 SEE ALSO
113
114C<datetime@perl.org> mailing list.
115
116http://datetime.perl.org/
117
118L<perl>, L<DateTime>,
119L<DateTime::Format::Builder>
120
121=head1 AUTHORS
122
123=over 4
124
125=item *
126
127Dave Rolsky <autarch@urth.org>
128
129=item *
130
131Iain Truskett
132
133=back
134
135=head1 COPYRIGHT AND LICENSE
136
137This software is Copyright (c) 2013 by Dave Rolsky.
138
139This is free software, licensed under:
140
141  The Artistic License 2.0 (GPL Compatible)
142
143=cut
144