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 17     17   125 use strictures 2;
  17         130  
  17         706  
3 17     17   3594 use Type::Library -base;
  17         36  
  17         118  
4 17     17   4380 use Types::Standard -types;
  17         33  
  17         138  
5 17     17   89665 use Type::Tiny::Class;
  17         46  
  17         622  
6 17     17   9234 use Time::Moment;
  17         25738  
  17         2042  
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