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   101 use strictures 2;
  17         124  
  17         626  
3 17     17   3334 use Type::Library -base;
  17         25  
  17         106  
4 17     17   3906 use Types::Standard -types;
  17         30  
  17         90  
5 17     17   73533 use Type::Tiny::Class;
  17         40  
  17         585  
6 17     17   8003 use Time::Moment;
  17         22988  
  17         1737  
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