| 1 | package Yukki::Types; | ||||||||||||||||||||
| 2 | 14 | $Yukki::Types::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 14 | ▶ | $Yukki::Types::VERSION = '0.991002';use v5.24; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 14 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 14 | use Type::Library -base, -declare => qw( | |||||||||||||||||||
| 8 | LoginName AccessLevel | ||||||||||||||||||||
| 9 | NavigationLinks NavigationMenuMap | ||||||||||||||||||||
| 10 | BaseURL BaseURLEnum BreadcrumbLinks RepositoryMap | ||||||||||||||||||||
| 11 | PluginConfig PluginList | ||||||||||||||||||||
| 12 | PrivilegesMap | ||||||||||||||||||||
| 13 | EmailAddress YukkiSettings | ||||||||||||||||||||
| 14 | YukkiWebSettings YukkiSettingsAnonymous | ||||||||||||||||||||
| 15 | 14 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 14 | ▶ | use Type::Utils qw( declare as where message coerce enum from via class_type ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 14 | ▶ | use Types::Standard qw( Str Int ArrayRef Maybe HashRef Dict ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 14 | ▶ | use Types::URI qw( Uri ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 14 | ▶ | use Email::Address; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 14 | ▶ | use List::Util qw( first all ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 14 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # ABSTRACT: standard types for use in Yukki | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | declare LoginName, | ||||||||||||||||||||
| 30 | as Str, | ||||||||||||||||||||
| 31 | 6 | ▶ | where { /^[a-zA-Z0-9_-]{3,20}$/ }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 0 | ▶ | message { "login name $_ must only contain letters and numbers" }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 14 | enum AccessLevel, [qw( read write none )]; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 14 | declare NavigationLinks, | |||||||||||||||||||
| 39 | as ArrayRef[ | ||||||||||||||||||||
| 40 | Dict[ | ||||||||||||||||||||
| 41 | label => Str, | ||||||||||||||||||||
| 42 | href => Str|Uri, | ||||||||||||||||||||
| 43 | sort => Maybe[Int], | ||||||||||||||||||||
| 44 | ], | ||||||||||||||||||||
| 45 | ]; | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 14 | declare NavigationMenuMap, | |||||||||||||||||||
| 49 | as HashRef[ NavigationLinks ]; | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 14 | enum BaseURLEnum, [qw( SCRIPT_NAME REWRITE )]; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 14 | declare BaseURL, as BaseURLEnum|Uri; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | coerce BaseURL, | ||||||||||||||||||||
| 57 | from Str, | ||||||||||||||||||||
| 58 | via { | ||||||||||||||||||||
| 59 | 0 | ▶ | $_ !~ /^(?:SCRIPT_NAME|REWRITE)$/ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 60 | && URI->new($_) | ||||||||||||||||||||
| 61 | 14 | }; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 14 | declare BreadcrumbLinks, | |||||||||||||||||||
| 65 | as ArrayRef[ | ||||||||||||||||||||
| 66 | Dict[ | ||||||||||||||||||||
| 67 | label => Str, | ||||||||||||||||||||
| 68 | href => Str, | ||||||||||||||||||||
| 69 | ], | ||||||||||||||||||||
| 70 | ]; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 14 | my $Repository = class_type 'Yukki::Settings::Repository'; | |||||||||||||||||||
| 74 | 14 | declare RepositoryMap, | |||||||||||||||||||
| 75 | as HashRef[$Repository]; | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | coerce RepositoryMap, | ||||||||||||||||||||
| 78 | from HashRef, | ||||||||||||||||||||
| 79 | via { | ||||||||||||||||||||
| 80 | 8 | ▶ | my $source = $_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 81 | +{ | ||||||||||||||||||||
| 82 | 8 | map { $_ => Yukki::Settings::Repository->new($source->{$_}) } | |||||||||||||||||||
| 83 | keys %$source | ||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 14 | }; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 14 | my $Privileges = class_type 'Yukki::Settings::Privileges'; | |||||||||||||||||||
| 89 | 14 | declare PrivilegesMap, | |||||||||||||||||||
| 90 | as HashRef[$Privileges]; | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | coerce PrivilegesMap, | ||||||||||||||||||||
| 93 | from HashRef, | ||||||||||||||||||||
| 94 | via { | ||||||||||||||||||||
| 95 | 7 | ▶ | my $source = $_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 96 | +{ | ||||||||||||||||||||
| 97 | 7 | map { $_ => Yukki::Settings::Privileges->new($source->{$_}) } | |||||||||||||||||||
| 98 | keys %$source | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | 14 | }; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | declare PluginConfig, | ||||||||||||||||||||
| 104 | as ArrayRef[HashRef], | ||||||||||||||||||||
| 105 | 0 | ▶ | where { all { defined $_->{module} } @$_ }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 14 | my $Plugin = class_type 'Yukki::Web::Plugin'; | |||||||||||||||||||
| 109 | declare PluginList, | ||||||||||||||||||||
| 110 | as ArrayRef[$Plugin], | ||||||||||||||||||||
| 111 | message { | ||||||||||||||||||||
| 112 | 0 | ▶ | return 'It is not an array of objects.' unless ref $_ eq 'ARRAY'; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||
| 113 | 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')
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')
| |||||||||||||||||||||
| 114 | 0 | @$_; | |||||||||||||||||||
| 115 | 0 | ▶ | $bad = blessed $bad if blessed $bad; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 0 | return "It contains $bad, which is not a Yukki::Web::Plugin."; | |||||||||||||||||||
| 117 | 14 | }; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 14 | class_type EmailAddress, { class => 'Email::Address' }; | |||||||||||||||||||
| 121 | coerce EmailAddress, | ||||||||||||||||||||
| 122 | from Str, | ||||||||||||||||||||
| 123 | 8 | ▶ | via { (Email::Address->parse($_))[0] }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 14 | class_type YukkiSettings, { class => 'Yukki::Settings' }; | |||||||||||||||||||
| 127 | coerce YukkiSettings, | ||||||||||||||||||||
| 128 | from HashRef, | ||||||||||||||||||||
| 129 | 8 | ▶ | via { Yukki::Settings->new($_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 14 | class_type YukkiWebSettings, { class => 'Yukki::Web::Settings' }; | |||||||||||||||||||
| 133 | coerce YukkiWebSettings, | ||||||||||||||||||||
| 134 | from HashRef, | ||||||||||||||||||||
| 135 | 0 | ▶ | via { Yukki::Web::Settings->new($_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 14 | class_type YukkiSettingsAnonymous, { class => 'Yukki::Settings::Anonymous' }; | |||||||||||||||||||
| 139 | coerce YukkiSettingsAnonymous, | ||||||||||||||||||||
| 140 | from HashRef, | ||||||||||||||||||||
| 141 | 8 | ▶ | via { Yukki::Settings::Anonymous->new($_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 14 | 1; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =pod | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =encoding UTF-8 | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =head1 NAME | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | Yukki::Types - standard types for use in Yukki | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =head1 VERSION | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | version 0.991_002 | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head1 SYNOPSIS | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | use Yukki::Types qw( LoginName AccessLevel ); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | has login_name => ( isa => LoginName ); | ||||||||||||||||||||
| 164 | has access_level => ( isa => AccessLevel ); | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head1 DESCRIPTION | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | A standard type library for Yukki. | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =head1 TYPES | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =head2 LoginName | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | This is a valid login name. Login names may only contain letters and numbers, as of this writing. | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =head2 AccessLevel | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | This is a valid access level. This includes any of the following values: | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | read | ||||||||||||||||||||
| 181 | write | ||||||||||||||||||||
| 182 | none | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head2 NavigationLinks | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | This is an array of hashes formatted like: | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | { | ||||||||||||||||||||
| 189 | label => 'Label', | ||||||||||||||||||||
| 190 | href => '/link/to/somewhere', | ||||||||||||||||||||
| 191 | sort => 40, | ||||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =head2 NavigationMenuMap | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | This is a hash of L</NavigationLinks>. | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =head2 BaseURL | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | This is either an absolute URL or the words C<SCRIPT_NAME> or C<REWRITE>. | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =head2 BreadcrumbLinks | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | This is an array of hashes formatted like: | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | { | ||||||||||||||||||||
| 207 | label => 'Label', | ||||||||||||||||||||
| 208 | href => '/link/to/somewhere', | ||||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | =head2 RepositoryMap | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | This is a hash of L<Yukki::Settings::Repository> objects. | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =head2 PrivilegeMap | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | This is a hash of L<Yukki::Settings::Privileges> objects. | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | =head2 PluginConfig | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | A plugin configuration is an array of hashes. Each hash must have at least one key named "module" defined. | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | =head2 PluginList | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | A plugin list is a loaded set of plugin objects. | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | =head1 COERCIONS | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | In addition to the types above, these coercions are provided for other types. | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | =head2 EmailAddress | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | Coerces a C<Str> into an L<Email::Address>. | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | =head2 YukkiSettings | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | Coerces a C<HashRef> into this object by passing the value to the constructor. | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | =head2 YukkiWebSettings | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | Coerces a C<HashRef> into a L<Yukki::Web::Settings>. | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | =head2 YukkiSettingsAnonymous | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | Coerces a C<HashRef> into this object by passing the value to the constructor. | ||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | =head1 AUTHOR | ||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 256 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | =cut | ||||||||||||||||||||