File Coverage

blib/lib/DateTimeX/Format/Excel/Types.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 39 39 100.0


line stmt bran cond sub pod time code
1             package DateTimeX::Format::Excel::Types;
2             our $AUTHORITY = 'cpan:JANDREW';
3 4     4   238545 use version; our $VERSION = version->declare("v0.14.0");
  4         1314  
  4         25  
4 4     4   349 use 5.010;
  4         10  
5 4     4   12 use strict;
  4         7  
  4         57  
6 4     4   12 use warnings;
  4         4  
  4         95  
7 4     4   1712 use Type::Utils -all;
  4         28628  
  4         32  
8             use Type::Library 1.000
9 4         23 -base,
10             -declare => qw(
11             DateTimeHash
12             DateTimeInstance
13             HashToDateTime
14             ExcelEpoch
15             SystemName
16 4     4   7393 );
  4         66  
17 4         19 use Types::Standard qw(
18             Str Dict Optional InstanceOf Int Num is_Num
19 4     4   2557 );
  4         31887  
20             my $try_xs =
21             exists($ENV{PERL_TYPE_TINY_XS}) ? !!$ENV{PERL_TYPE_TINY_XS} :
22             exists($ENV{PERL_ONLY}) ? !$ENV{PERL_ONLY} :
23             1;
24             if( $try_xs and exists $INC{'Type/Tiny/XS.pm'} ){
25 1     1   5 eval "use Type::Tiny::XS 0.010";
  1         17  
  1         14  
26             if( $@ ){
27             die "You have loaded Type::Tiny::XS but versions prior to 0.010 will cause this module to fail";
28             }
29             }
30 4     4   3445 use DateTime;
  4         5  
  4         156  
31             if( $ENV{ Smart_Comments } ){
32 4     4   16 use Smart::Comments -ENV;
  4         6  
  4         31  
33             ### Smart-Comments turned on for DateTimeX-Format-Excel-Types ...
34             }
35              
36             #########1 Package Variables 3#########4#########5#########6#########7#########8#########9
37              
38              
39              
40             #########1 Type Library 3#########4#########5#########6#########7#########8#########9
41              
42             declare DateTimeHash,
43             as Dict[
44             year => Int,
45             month => Optional[ Int ],
46             day => Optional[ Int ],
47             hour => Optional[ Int ],
48             minute => Optional[ Int ],
49             second => Optional[ Int ],
50             nanosecond => Optional[ Int ],
51             time_zone => Optional[ Str ],
52             ];
53              
54             declare DateTimeInstance,
55             as InstanceOf[ "DateTime" ];
56              
57             declare_coercion HashToDateTime,
58             to_type DateTimeInstance,
59             from DateTimeHash,
60             q{ DateTime->new( $_ ) };
61              
62             declare ExcelEpoch,
63             as Num,
64             where{ $_ >= 0 },
65             message{
66             ( !defined $_ ) ? "No value passed" :
67             ( !is_Num( $_ ) ) ? "-$_- is not a Number" :
68             "-$_- is less than 0"
69             };
70              
71             declare SystemName,
72             as Str,
73             where{ $_ =~ /^(win_excel|apple_excel)$/ };
74              
75             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
76              
77              
78              
79             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
80              
81              
82              
83             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
84              
85             1;
86              
87             #########1 Documentation 3#########4#########5#########6#########7#########8#########9
88             __END__
89              
90             =head1 NAME
91              
92             DateTimeX::Format::Excel::Types::Types - A Type::Tiny Excel DateTime type library
93              
94             =head1 DESCRIPTION
95              
96             This is a type library for L<DateTimeX::Format::Excel> It doesn't really have good context
97             outside of that. It is built on L<Type::Tiny>.
98              
99             =head2 L<Caveat utilitor|http://en.wiktionary.org/wiki/Appendix:List_of_Latin_phrases_(A%E2%80%93E)#C>
100              
101             All type tests included with this package are considered to be the fixed definition of
102             the types. Any definition not included in the testing is considered flexible.
103              
104             This module uses L<Type::Tiny> which can, in the background, use L<Type::Tiny::XS>.
105             While in general this is a good thing you will need to make sure that
106             Type::Tiny::XS is version 0.010 or newer since the older ones didn't support the
107             'Optional' method.
108              
109             =head2 Types
110              
111             =head3 DateTimeHash
112              
113             =over
114              
115             B<Definition:> How to know if a hash meets the DateTime hash requirements
116              
117             B<Range>
118              
119             Dict[
120             year => Int,
121             month => Optional[ Int ],
122             day => Optional[ Int ],
123             hour => Optional[ Int ],
124             minute => Optional[ Int ],
125             second => Optional[ Int ],
126             nanosecond => Optional[ Int ],
127             time_zone => Optional[ Str ],
128             ]
129              
130             =back
131              
132             =head3 DateTimeInstance
133              
134             =over
135              
136             B<Definition:> An instance of a L<DateTime> object
137              
138             =back
139              
140             =head3 ExcelEpoch
141              
142             =over
143              
144             B<Definition:> Numbers used by Microsoft Excel to descibe a point in time.
145              
146             B<Range> All numbers greater than or equal to 0
147              
148             =back
149              
150             =head3 SystemName
151              
152             =over
153              
154             B<Definition:> labels for the different Excel calculation rules and epoch start.
155              
156             B<Range> win_excel|apple_excel
157              
158             =back
159              
160             =head2 Named Coercions
161              
162             =head3 HashToDateTime
163              
164             =over
165              
166             B<Accepts: > A DateTimeHash
167              
168             B<Returns: > A L<DateTime> instance
169              
170             B<Conversion Method: > DateTime->new( $DateTimeHash );
171              
172             =back
173              
174             =head1 SUPPORT
175              
176             =over
177              
178             L<github DateTimeX::Format::Excel/issues|https://github.com/jandrew/DateTimeX-Format-Excel/issues>
179              
180             =back
181              
182             =head1 TODO
183              
184             =over
185              
186             B<1.> Nothing L<yet|/SUPPORT>
187              
188             =back
189              
190             =head1 AUTHOR
191              
192             =over
193              
194             =item Jed Lund
195              
196             =item jandrew@cpan.org
197              
198             =back
199              
200             =head1 COPYRIGHT
201              
202             This program is free software; you can redistribute
203             it and/or modify it under the same terms as Perl itself.
204              
205             The full text of the license can be found in the
206             LICENSE file included with this module.
207              
208             This software is copyrighted (c) 2014, 2015 by Jed Lund
209              
210             =head1 DEPENDENCIES
211              
212             =over
213              
214             L<version>
215              
216             L<DateTime>
217              
218             L<Type::Utils>
219              
220             L<Type::Library>
221              
222             L<Types::Standard>
223              
224             =back
225              
226             =head1 SEE ALSO
227              
228             =over
229              
230             L<DateTime::Format::Excel>
231              
232             L<Smart::Comments> - Turned on with $ENV{ Smart_Comments }
233              
234             =back
235              
236             =cut
237              
238             #########1#########2 main pod documentation end 5#########6#########7#########8#########9