| 1 | package Feed::Pipe::Typedefs; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 5 | our $VERSION = '1.003'; | |||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use DateTime::Locale; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use DateTime::TimeZone; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use DateTime::Format::HTTP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use XML::Atom::Feed; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | ▶ | use MooseX::Types -declare => [qw( AtomEntry AtomFeed Datetime Timezone Uri )]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | ▶ | use MooseX::Types::Moose qw/ArrayRef FileHandle HashRef Num ScalarRef Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 5 | class_type AtomFeed, {class => 'XML::Atom::Feed'}; | |||||||||
| 16 | 5 | class_type AtomEntry, {class => 'XML::Atom::Entry'}; | |||||||||
| 17 | 5 | class_type Datetime, {class => "DateTime"}; | |||||||||
| 18 | 5 | class_type Timezone, {class => "DateTime::TimeZone"}; | |||||||||
| 19 | 5 | class_type Uri, {class => "URI"}; | |||||||||
| 20 | |||||||||||
| 21 | # Feed constructor is pretty flexible | ||||||||||
| 22 | coerce AtomFeed, | ||||||||||
| 23 | 0 | ▶ | from ScalarRef, via { XML::Atom::Feed->new($_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 0 | ▶ | from Str, via { XML::Atom::Feed->new($_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 25 | 0 | ▶ | from FileHandle, via { XML::Atom::Feed->new($_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 26 | 0 | ▶ | from Uri, via { XML::Atom::Feed->new($_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 5 | ; | |||||||||
| 28 | coerce Datetime, | ||||||||||
| 29 | 0 | ▶ | from Num, via { DateTime->from_epoch( epoch => $_ ) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | 0 | ▶ | from HashRef, via { DateTime->new( %$_ ) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 31 | 0 | ▶ | from Str, via { DateTime::Format::HTTP->parse_datetime($_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 5 | ; | |||||||||
| 33 | coerce Timezone, | ||||||||||
| 34 | 0 | ▶ | from Str, via { DateTime::TimeZone->new( name => $_ ) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 5 | ; | |||||||||
| 36 | |||||||||||
| 37 | # optionally add Getopt option type | ||||||||||
| 38 | 5 | eval { require MooseX::Getopt; }; | |||||||||
| 39 | 5 | ▶ | if ( !$@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', ) | ||||||||||
| 41 | 0 | for ( Datetime, Timezone ); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 5 | 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 | |||||||||||