blib/lib/Statocles/Types.pm

filter: Statementstmt 100% 89 / 89 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 27 / 27 Podpod 0.0% 0 / 1 totaltotal 99.2% 125 / 126 CC 4 SCAR 2.4
CC
4
Cov
100%
__ANON__
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Statocles/App/Static.pm ↑ Summary blib/lib/Statocles/Base.pm »
1 package Statocles::Types;
2 101 our $VERSION = '0.099';
3 # ABSTRACT: Type constraints and coercions for Statocles
4  
5 101 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 101 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 101 ▶use feature qw( :5.10 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 101 ▶use Type::Library -base, -declare => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 StoreType ThemeType LinkType LinkArray LinkHash LinkTree LinkTreeArray
10 DateTimeObj DateStr DateTimeStr
11 PersonType
12 PagePath
13 101 );
14 101 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 101 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 101 ▶use DateTime::Moonpig;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 101 ▶use Mojo::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 101 class_type StoreType, { class => "Statocles::Store" };
20 28 ▶coerce StoreType, from Str, via { Statocles::Store->new( path => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
21 35 ▶coerce StoreType, from InstanceOf['Path::Tiny'], via { Statocles::Store->new( path => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
22  
23 101 class_type ThemeType, { class => "Statocles::Theme" };
24 2 ▶coerce ThemeType, from Str, via { require Statocles::Theme; Statocles::Theme->new( store => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
25 35 ▶coerce ThemeType, from InstanceOf['Path::Tiny'], via { require Statocles::Theme; Statocles::Theme->new( store => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27 101 class_type LinkType, { class => "Statocles::Link" };
28 36 ▶coerce LinkType, from HashRef, via { Statocles::Link->new( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
29 13 ▶coerce LinkType, from Str, via { Statocles::Link->new( href => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
30  
31 101 class_type LinkTree, { class => "Statocles::Link::Tree" };
32 5 ▶coerce LinkTree, from HashRef, via { Statocles::Link::Tree->new( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 3 ▶coerce LinkTree, from Str, via { Statocles::Link::Tree->new( href => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
34  
35 101 class_type PersonType, { class => 'Statocles::Person' };
36 1 ▶coerce PersonType, from HashRef, via { Statocles::Person->new( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
37 15 ▶coerce PersonType, from Str, via { Statocles::Person->new( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 101 declare LinkArray, as ArrayRef[LinkType], coerce => 1;
40 coerce LinkArray, from ArrayRef[HashRef|Str],
41 28 ▶ via {
Subroutine __ANON__: called CC=3 SCAR=11.0
42 28 ▶ [ map { ref $_ eq 'HASH' && exists $_->{children} ? LinkTree->coerce($_) : LinkType->coerce( $_ ) } @$_ ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' && exists $_->{'children'} ? : 1 34 35
Condition100%3/3
ref $_ eq "HASH" and exists $_->{"children"}
!ll&&!rl&&r
3311
MC/DC100%2/2
ref $_ eq "HASH" and exists $_->{"children"}
ref $_ eq "HASH" exists $_->{"children"}
Truth table100%3/3
A and B
A= ref $_ eq "HASH"B= exists $_->{"children"}
ABresult
0X0
100
111
43 101 };
44  
45 101 declare LinkHash, as HashRef[LinkArray], coerce => 1;
46 # We need the parens in this "from" type union to fix an issue in Perl
47 # < 5.14 and Type::Tiny 1.000005
48 # (https://github.com/tobyink/p5-type-tiny/issues/29)
49 coerce LinkHash, from HashRef[(ArrayRef[HashRef|Str]|HashRef)|Str],
50 21 ▶ via {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 21 my %hash = %$_;
52 my $out = {
53 21 ▶ ( map {; $_ => LinkArray->coerce( ref $hash{ $_ } ne 'ARRAY' ? [ $hash{ $_ } ] : $hash{ $_ } ) } keys %hash ),
Branch: 1 branch
BranchTrueFalseTotal
ref $hash{$_} ne 'ARRAY' ? : 5 22 27
54 };
55 21 return $out;
56 101 };
57  
58 101 declare LinkTreeArray, as ArrayRef[LinkTree], coerce => 1;
59 coerce LinkTreeArray, from ArrayRef[HashRef|Str],
60 3 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 3 [ map { LinkTree->coerce( $_ ) } @$_ ];
62 101 };
63  
64 101 class_type DateTimeObj, { class => 'DateTime::Moonpig' };
65 18 ▶declare DateStr, as Str, where { m{^\d{4}-?\d{2}-?\d{2}$} };
Subroutine __ANON__: called CC=1 SCAR=0.0
66 9 ▶declare DateTimeStr, as Str, where { m{^\d{4}-?\d{2}-?\d{2}[T ]\d{2}:?\d{2}:?\d{2}} };
Subroutine __ANON__: called CC=1 SCAR=0.0
67 9 ▶coerce DateTimeObj, from DateStr, via {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 9 my ( $y, $m, $d ) = $_ =~ /^(\d{4})[-]?(\d{2})[-]?(\d{2})$/;
69 9 DateTime::Moonpig->new(
70 year => $y,
71 month => $m,
72 day => $d,
73 );
74 101 };
75 8 ▶coerce DateTimeObj, from DateTimeStr, via {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 8 my ( $y, $m, $d, $h, $n, $s ) = $_ =~ /^(\d{4})[-]?(\d{2})[-]?(\d{2})[T ]?(\d{2}):?(\d{2}):?(\d{2})/;
77 8 DateTime::Moonpig->new(
78 year => $y,
79 month => $m,
80 day => $d,
81 hour => $h,
82 minute => $n,
83 second => $s,
84 );
85 101 };
86  
87 101 class_type PagePath, { class => "Mojo::Path" };
88 307 ▶coerce PagePath, from Str, via { Mojo::Path->new( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
89  
90 1 ▶sub DateTime::Moonpig::tzoffset {
Subroutine tzoffset: called CC=1 SCAR=0.0
Pod undocumented
91 1 my ( $self ) = @_;
92 1 warn "The tzoffset shim method will be removed in Statocles version 2.0. See Statocles::Help::Upgrading for instructions to remove this warning.\n";
93 1 return $self->offset * 100;
94 }
95  
96 # Down here to resolve circular dependencies
97 101 require Statocles::Store;
98 101 require Statocles::Link;
99 101 require Statocles::Link::Tree;
100 101 require Statocles::Person;
101 101 require Statocles::Image;
102  
103 101 1;
104  
105 __END__
« blib/lib/Statocles/App/Static.pm ↑ Summary blib/lib/Statocles/Base.pm »