blib/lib/Yukki/Types.pm

filter: Statementstmt 86.2% 69 / 80 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 68.0% 17 / 25 Podpod n/a totaltotal 74.1% 86 / 116 CC 5 SCAR 10.5
CC
5
Cov
78%
__ANON__
12.0
__ANON__
6.0
__ANON__
6.0
CRAP 2.9
« blib/lib/Yukki/Model/Remote.pm ↑ Summary blib/lib/Yukki/Model/User.pm »
1 package Yukki::Types;
2 21 $Yukki::Types::VERSION = '0.991_007'; # TRIAL
3 21 $Yukki::Types::VERSION = '0.991007';
4 21 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Type::Library -base, -declare => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 LoginName AccessLevel
9 NavigationLinks NavigationMenuMap
10 BaseURL BaseURLEnum BreadcrumbLinks
11 RepositoryName RepositoryMap
12 PluginConfig PluginList
13 PrivilegesMap
14 EmailAddress YukkiSettings
15 YukkiWebSettings YukkiSettingsAnonymous
16 21 );
17 21 ▶use Type::Utils qw( declare as where message coerce enum from via class_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 21 ▶use Types::Standard qw( Str Int ArrayRef Maybe Map HashRef Dict );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 ▶use Types::URI qw( Uri );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 21 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 21 ▶use List::Util qw( first all );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 21 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # ABSTRACT: standard types for use in Yukki
28  
29  
30 declare LoginName,
31 as Str,
32 7 ▶ where { /^[a-zA-Z0-9_-]{3,20}$/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 0 ▶ message { "login name $_ must only contain letters and numbers" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
34  
35  
36 21 enum AccessLevel, [qw( read write none )];
37  
38  
39 21 declare NavigationLinks,
40 as ArrayRef[
41 Dict[
42 label => Str,
43 href => Str|Uri,
44 sort => Maybe[Int],
45 ],
46 ];
47  
48  
49 21 declare NavigationMenuMap,
50 as HashRef[ NavigationLinks ];
51  
52  
53 21 enum BaseURLEnum, [qw( SCRIPT_NAME REWRITE )];
54  
55 21 declare BaseURL, as BaseURLEnum|Uri;
56  
57 coerce BaseURL,
58 from Str,
59 0 ▶ via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 ▶ $_ !~ /^(?:SCRIPT_NAME|REWRITE)$/
Branch: 1 branch
BranchTrueFalseTotal
not $_ =~ /^(?:SCRIPT_NAME|REWRITE)$/u and "URI"->new($_) 0 0 0
61 && URI->new($_)
62 21 };
63  
64  
65 21 declare BreadcrumbLinks,
66 as ArrayRef[
67 Dict[
68 label => Str,
69 href => Str,
70 ],
71 ];
72  
73  
74 declare RepositoryName,
75 as Str,
76 89 ▶ where { /^[a-zA-Z0-9_.-]{3,50}$/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 0 ▶ message { "repository name $_ must only contain letters, numbers, and periods" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
78  
79  
80 21 my $Repository = class_type 'Yukki::Settings::Repository';
81 21 declare RepositoryMap,
82 as Map[RepositoryName, $Repository];
83  
84 coerce RepositoryMap,
85 from HashRef,
86 11 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 11 my $source = $_;
88 +{
89 11 map { $_ => Yukki::Settings::Repository->new($source->{$_}) }
90 keys %$source
91 }
92 21 };
93  
94  
95 21 my $Privileges = class_type 'Yukki::Settings::Privileges';
96 21 declare PrivilegesMap,
97 as HashRef[$Privileges];
98  
99 coerce PrivilegesMap,
100 from HashRef,
101 10 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 10 my $source = $_;
103 +{
104 10 map { $_ => Yukki::Settings::Privileges->new($source->{$_}) }
105 keys %$source
106 }
107 21 };
108  
109  
110 declare PluginConfig,
111 as ArrayRef[HashRef],
112 0 ▶ where { all { defined $_->{module} } @$_ };
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
113  
114  
115 21 my $Plugin = class_type 'Yukki::Web::Plugin';
116 declare PluginList,
117 as ArrayRef[$Plugin],
118 0 ▶ message {
Subroutine __ANON__: not called CC=3 SCAR=24.8
119 0 ▶ return 'It is not an array of objects.' unless ref $_ eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" 0 0 0
120 0 ▶ my $bad = first { not blessed $_ or not $_->isa('Yukki::Web::Plugin') }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$_->blessed && $_->isa('Yukki::Web::Plugin')
!ll&&!rl&&r
000
MC/DC0%0/2
$_->blessed && $_->isa('Yukki::Web::Plugin')
$_->blessed $_->isa('Yukki::Web::Plugin')
Truth table0%0/3
A && B
A= $_->blessedB= $_->isa('Yukki::Web::Plugin')
ABresult
0X0
100
111
121 0 @$_;
122 0 ▶ $bad = blessed $bad if blessed $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad->blessed 0 0 0
123 0 return "It contains $bad, which is not a Yukki::Web::Plugin.";
124 21 };
125  
126  
127 21 class_type EmailAddress, { class => 'Email::Address' };
128 coerce EmailAddress,
129 from Str,
130 11 ▶ via { (Email::Address->parse($_))[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
131  
132  
133 21 class_type YukkiSettings, { class => 'Yukki::Settings' };
134 coerce YukkiSettings,
135 from HashRef,
136 11 ▶ via { Yukki::Settings->new($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
137  
138  
139 21 class_type YukkiWebSettings, { class => 'Yukki::Web::Settings' };
140 coerce YukkiWebSettings,
141 from HashRef,
142 0 ▶ via { Yukki::Web::Settings->new($_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
143  
144  
145 21 class_type YukkiSettingsAnonymous, { class => 'Yukki::Settings::Anonymous' };
146 coerce YukkiSettingsAnonymous,
147 from HashRef,
148 11 ▶ via { Yukki::Settings::Anonymous->new($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
149  
150 21 1;
151  
152 __END__
« blib/lib/Yukki/Model/Remote.pm ↑ Summary blib/lib/Yukki/Model/User.pm »