File Coverage

blib/lib/Feed/Pipe/Typedefs.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Feed::Pipe::Typedefs;
2 5     5   363735 use strict;
  5         15  
  5         309  
3              
4             our $VERSION = '1.003';
5              
6 5     5   8944 use DateTime;
  5         696658  
  5         195  
7 5     5   88 use DateTime::Locale;
  5         10  
  5         86  
8 5     5   25 use DateTime::TimeZone;
  5         10  
  5         97  
9 5     5   4813 use DateTime::Format::HTTP;
  5         30931  
  5         169  
10 5     5   4316 use XML::Atom::Feed;
  0            
  0            
11              
12             use MooseX::Types -declare => [qw( AtomEntry AtomFeed Datetime Timezone Uri )];
13             use MooseX::Types::Moose qw/ArrayRef FileHandle HashRef Num ScalarRef Str/;
14              
15             class_type AtomFeed, {class => 'XML::Atom::Feed'};
16             class_type AtomEntry, {class => 'XML::Atom::Entry'};
17             class_type Datetime, {class => "DateTime"};
18             class_type Timezone, {class => "DateTime::TimeZone"};
19             class_type Uri, {class => "URI"};
20              
21             # Feed constructor is pretty flexible
22             coerce AtomFeed,
23             from ScalarRef, via { XML::Atom::Feed->new($_) },
24             from Str, via { XML::Atom::Feed->new($_) },
25             from FileHandle, via { XML::Atom::Feed->new($_) },
26             from Uri, via { XML::Atom::Feed->new($_) },
27             ;
28             coerce Datetime,
29             from Num, via { DateTime->from_epoch( epoch => $_ ) },
30             from HashRef, via { DateTime->new( %$_ ) },
31             from Str, via { DateTime::Format::HTTP->parse_datetime($_) },
32             ;
33             coerce Timezone,
34             from Str, via { DateTime::TimeZone->new( name => $_ ) },
35             ;
36              
37             # optionally add Getopt option type
38             eval { require MooseX::Getopt; };
39             if ( !$@ ) {
40             MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', )
41             for ( Datetime, Timezone );
42             }
43              
44             1;
45             __END__
46              
47             =head1 NAME
48              
49             Feed::Pipe::Typedefs - Moose Types and coercions for Feed::Pipe
50              
51             =head1 SYNOPSIS
52              
53             use Feed::Pipe::Typedefs qw(AtomEntry AtomFeed);
54              
55             =head1 ABSTRACT
56              
57             Note: This is just a support library. You should never need to use it
58             yourself, but it's documented for your curiosity anyway.
59              
60             You probably do not want use this module directly. Instead use
61             L<Feed::Pipe::Types>, which combines everything here with other more
62             general types into one handy bundle.
63              
64             =head1 TYPES AND COERCIONS
65              
66             This module exports the following types and coercions.
67              
68             =head2 AtomEntry
69              
70             A class type of XML::Atom::Entry, with no declared coercions.
71              
72             =head2 AtomFeed
73              
74             A class type of XML::Atom::Feed, with declared coercions from ScalarRef,
75             Str, FileHandle, and Uri.
76              
77             =head2 Datetime
78              
79             A class type of DateTime, with declared coercions from Num, HashRef,
80             and Str. Note: you may want to use L<MooseX::Types::DateTime> instead.
81             I did not, because A) I don't like type constraint names being identical
82             to class names when conversions are declared, and B) I wanted some custom
83             coercions that may not be suitable for all applications, namely, coercion
84             from Str using L<DateTime::Format::HTTP>.
85              
86             =head2 Timezone
87              
88             A class type of DateTime::TimeZone, with declared coercions from Str. Just
89             for completeness to complement Datetime.
90              
91             =head2 Uri
92              
93             A class type of URI, with no declared coercions. See L<MooseX::Types::URI>
94             if you need coercions.
95              
96             =head1 SEE ALSO
97              
98             L<Feed::Pipe::Types>, L<MooseX::Types::DateTime>, L<MooseX::Types::ISO8601>,
99             L<DateTime::Format::HTTP>, L<MooseX::Types::URI>
100              
101             =head1 AUTHOR
102              
103             Vince Veselosky, C<< <vince at control-escape.com> >>
104              
105             =head1 COPYRIGHT & LICENSE
106              
107             Copyright 2009 Vince Veselosky.
108              
109             This program is distributed under the MIT (X11) License:
110             L<http://www.opensource.org/licenses/mit-license.php>
111              
112             Permission is hereby granted, free of charge, to any person
113             obtaining a copy of this software and associated documentation
114             files (the "Software"), to deal in the Software without
115             restriction, including without limitation the rights to use,
116             copy, modify, merge, publish, distribute, sublicense, and/or sell
117             copies of the Software, and to permit persons to whom the
118             Software is furnished to do so, subject to the following
119             conditions:
120              
121             The above copyright notice and this permission notice shall be
122             included in all copies or substantial portions of the Software.
123              
124             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
125             EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
126             OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
127             NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
128             HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
129             WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
130             FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
131             OTHER DEALINGS IN THE SOFTWARE.
132              
133              
134             =cut
135              
136              
137