File Coverage

blib/lib/WebService/Box/Types/Library.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 28 28 100.0


line stmt bran cond sub pod time code
1             package WebService::Box::Types::Library;
2              
3 9     9   1590 use strict;
  9         19  
  9         298  
4 9     9   44 use warnings;
  9         18  
  9         422  
5              
6             use Type::Library
7 9         91 -base,
8             -declare => qw(
9             BoxPerson PersonHash Timestamp BoxFolderHash BoxFileHash
10             OptionalStr OptionalInt OptionalTimestamp
11             SharedLink SharedLinkHash SharedLinkPermissionHash
12 9     9   1916 );
  9         66987  
13              
14 9     9   26853 use Type::Utils -all;
  9         46634  
  9         115  
15 9     9   33172 use Types::Standard -types;
  9         101542  
  9         92  
16              
17 9     9   54949 use DateTime;
  9         1410577  
  9         412  
18              
19 9     9   5814 use WebService::Box::Types::By;
  9         198  
  9         12769  
20              
21             our $VERSION = 0.01;
22              
23              
24             # create some basic types
25             {
26             declare OptionalStr => as union[ Undef, Str ];
27             declare OptionalInt => as union[ Undef, Int ];
28             }
29              
30             # create types regarding users
31             {
32             class_type BoxPerson => { class => "WebService::Box::Types::By" };
33              
34             declare PersonHash =>
35             as Dict[
36             type => Str,
37             id => Int,
38             name => Str,
39             login => Str,
40             ];
41              
42             coerce BoxPerson =>
43             from PersonHash => via { WebService::Box::Types::By->new( %{$_} ) };
44             }
45              
46              
47             # create types regarding times
48             {
49             class_type Timestamp => { class => "DateTime" };
50              
51             coerce Timestamp =>
52             from Str() => via {
53             my ($timezone) = $_ =~ m{([+-][0-9]{2}:?[0-9]{2})\z};
54             $timezone = '' if !defined $timezone;
55             $timezone =~ s{:}{};
56              
57             my %opts;
58             $opts{time_zone} = $timezone if defined $timezone and $timezone ne '';
59              
60             my ($year,$month,$day,$hour,$minute,$second) = split /[:T+-]/, $_;
61             DateTime->new(
62             second => $second,
63             minute => $minute,
64             hour => $hour,
65             day => $day,
66             month => $month,
67             year => $year,
68             %opts,
69             );
70             };
71              
72             declare OptionalTimestamp => as union[Timestamp, Undef];
73             }
74              
75             {
76             declare BoxFolderHash =>
77             as Dict[
78             type => sub{ $_ eq 'folder' },
79             id => Str,
80             sequence_id => OptionalStr,
81             etag => OptionalStr,
82             name => Str,
83             ];
84              
85             declare BoxFileHash =>
86             as Dict[
87             type => sub{ $_ eq 'file' },
88             id => Str,
89             sequence_id => OptionalStr,
90             etag => OptionalStr,
91             name => Str,
92             ];
93             }
94              
95             {
96             # shared link objects
97             class_type SharedLink => { class => 'WebService::Box::Types::SharedLink' };
98              
99             declare SharedLinkPermissionHash =>
100             as Dict[
101             can_download => Str,
102             can_preview => Str,
103             ];
104              
105             declare SharedLinkHash =>
106             as Dict[
107             url => Str,
108             download_url => Str,
109             vanity_url => OptionalStr,
110             is_password_enabled => OptionalStr,
111             unshared_at => OptionalTimestamp,
112             download_count => Int,
113             preview_count => Int,
114             access => Str,
115             permissions => SharedLinkPermissionHash,
116             ];
117              
118             require WebService::Box::Types::SharedLink;
119              
120             coerce SharedLink
121             from SharedLinkHash => via {
122             WebService::Box::Types::SharedLink->new( %{$_} );
123             };
124             }
125              
126             1;
127              
128             __END__