File Coverage

lib/Finance/Alpaca/Types.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Finance::Alpaca::Types 0.9902 {
2 1     1   9 use strictures 2;
  1         10  
  1         44  
3 1     1   229 use Type::Library -base;
  1         2  
  1         6  
4 1     1   317 use Types::Standard -types;
  1         2  
  1         6  
5 1     1   5119 use Type::Tiny::Class;
  1         3  
  1         33  
6 1     1   484 use Time::Moment;
  1         1463  
  1         112  
7             our @EXPORT = qw[Timestamp];
8              
9             # Type::Tiny::Class is a subclass of Type::Tiny for creating
10             # InstanceOf-like types. It's kind of better though because
11             # it does cool stuff like pass through $type->new(%args) to
12             # the class's constructor.
13             #
14             my $dt = __PACKAGE__->add_type(
15             Type::Tiny::Class->new( name => 'Timestamp', class => 'Time::Moment', ) );
16              
17             # Can't just use "plus_coercions" method because that creates
18             # a new anonymous child type to add the coercions to. We want
19             # to add them to the type which exists in this library.
20             #
21             $dt->coercion->add_type_coercions(
22              
23             #Undef() => q[Time::Moment->now()],
24             Int() => q[Time::Moment->from_epoch($_)],
25             Str() => q[Time::Moment->from_string($_)]
26             );
27             __PACKAGE__->make_immutable;
28             };
29             1;
30              
31             # No need for docs as this is internal