| 1 | package Params::Registry::Types; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Set::Scalar; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Set::Infinite; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use DateTime::Span; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use DateTime::SpanSet; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Moose::Util::TypeConstraints qw(class_type); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 1 | our @TYPES; | |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 24 | 1 | @TYPES = qw(Type Template TemplateSet Dependency Format XSDdate | |||||||||||||||||||||||||||||||||||
| 25 | XSDgYearMonth XSDgYear XSDgMonth XSDgDay DateSpan | ||||||||||||||||||||||||||||||||||||
| 26 | DateSpanSet DateRange Currency Decimal3 XSDBool | ||||||||||||||||||||||||||||||||||||
| 27 | NumberRange Set IntSet LCToken UCToken TokenSet | ||||||||||||||||||||||||||||||||||||
| 28 | PositiveInt NegativeInt NonPositiveInt | ||||||||||||||||||||||||||||||||||||
| 29 | NonNegativeInt); | ||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use MooseX::Types::Moose qw(ClassName RoleName ArrayRef HashRef CodeRef | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 33 | 1 | Undef Maybe Bool Num Int Str); | |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use MooseX::Types -declare => [@TYPES]; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||
| 37 | # for Set::Infinite | ||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use constant INF => Set::Infinite->inf; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use constant NEG_INF => Set::Infinite->minus_inf; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | Params::Registry::Types - Types for Params::Registry | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | Version 0.03 | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | use Params::Registry::Types qw(:all); | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | =head1 TYPES | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | =head2 Type | ||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | This is the type for types. XZibit-approved. | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 1 | class_type 'MooseX::Types::UndefinedType'; | |||||||||||||||||||||||||||||||||||
| 67 | 1 | class_type 'MooseX::Types::TypeDecorator'; | |||||||||||||||||||||||||||||||||||
| 68 | 1 | class_type 'Moose::Meta::TypeConstraint'; | |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | 1 | subtype Type, as join('|', qw( MooseX::Types::UndefinedType | |||||||||||||||||||||||||||||||||||
| 71 | MooseX::Types::TypeDecorator | ||||||||||||||||||||||||||||||||||||
| 72 | Moose::Meta::TypeConstraint | ||||||||||||||||||||||||||||||||||||
| 73 | ClassName RoleName Str )); | ||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | # yo dawg i herd u liek types so we put a type in yo type so u can | ||||||||||||||||||||||||||||||||||||
| 76 | # type whiel u type | ||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | coerce Type, from Str, via { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $x = shift; | |||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return Moose::Util::TypeConstraints::find_or_parse_type_constraint($x) | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
Moose::Util::TypeConstraints::find_or_parse_type_constraint($x) || class_type($x)
MC/DC0%0/2
Moose::Util::TypeConstraints::find_or_parse_type_constraint($x) || class_type($x)
Moose::Util::TypeConstraints::find_or_parse_type_constraint($x)
class_type($x)
Truth table0%0/3
A || B
A= Moose::Util::TypeConstraints::find_or_parse_type_constraint($x)B= class_type($x)
| |||||||||||||||||||||||||||||||||||||
| 80 | || class_type($x); | ||||||||||||||||||||||||||||||||||||
| 81 | 1 | }; | |||||||||||||||||||||||||||||||||||
| 82 | # ...that meme will never get old. | ||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | =head2 Dependency | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | A dependency is just a set of keys that both maintains its order and | ||||||||||||||||||||||||||||||||||||
| 87 | can be conveniently queried for membership. It is implemented via | ||||||||||||||||||||||||||||||||||||
| 88 | L<Tie::IxHash>. | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | subtype Dependency, as HashRef[Bool], | ||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | where { my $tied = tied %$_; $tied && $tied->isa('Tie::IxHash') }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub ixhash_ref { | ||||||||||||||||||||||||||||||||||
|
Subroutine
ixhash_ref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 96 | 0 | tie my %ix, 'Tie::IxHash', @_; | |||||||||||||||||||||||||||||||||||
| 97 | 0 | \%ix; | |||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | coerce Dependency, from Str, via { ixhash_ref($_[0] => 1) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | coerce Dependency, from ArrayRef, via { ixhash_ref(map { $_ => 1 } @{$_[0]}) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | # actually we don't want this to be exposed because we're usin g | ||||||||||||||||||||||||||||||||||||
| 105 | # meaning | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | # coerce Dependency, from HashRef, | ||||||||||||||||||||||||||||||||||||
| 108 | # via { tie my %ix, 'Tie::IxHash', %{$_[0]}; \%ix }; | ||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | =head2 Template | ||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | This might not be used currently, i don't remember | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||
| 117 | 1 | class_type Template, { class => 'Params::Registry::Template' }; | |||||||||||||||||||||||||||||||||||
| 118 | #coerce Template, from HashRef, via { Params::Registry::Template->new(shift) }; | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | #subtype TemplateSet, as HashRef[HashRef]; | ||||||||||||||||||||||||||||||||||||
| 121 | #coerce TemplateSet, | ||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||
| 123 | =head2 Format | ||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 1 | subtype Format, as CodeRef; | |||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | coerce Format, from Str, via { my $x = shift; sub { sprintf $x, shift } }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | =head2 PositiveInt | ||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | subtype PositiveInt, as Int, where { $_ > 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||
| 136 | =head2 NegativeInt | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | subtype NegativeInt, as Int, where { $_ < 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||
| 142 | =head2 NonPostiveInt | ||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | subtype NonPositiveInt, as Int, where { $_ <= 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||
| 148 | =head2 NonNegativeInt | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | subtype NonNegativeInt, as Int, where { $_ >= 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||
| 154 | =head2 XSDdate | ||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||
| 158 | 1 | class_type XSDdate, { class => 'DateTime' }; | |||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _make_date { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_make_date: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 162 | 0 | DateTime->last_day_of_month(year => $_[0], month => $_[1]); | |||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||
| 165 | 0 | DateTime->new(year => $_[0], month => $_[1], day => $_[2]); | |||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | coerce XSDdate, from Str, via { _make_date(split /-+/, $_[0]) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | =head2 XSDgYearMonth | ||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | 1 | subtype XSDgYearMonth, as XSDdate; | |||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | coerce XSDgYearMonth, from Str, via { _make_date(split(/-/, $_[0], 2)) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||
| 179 | =head2 XSDgYear | ||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 1 | subtype XSDgYear, as Int; | |||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | =head2 XSDgMonth | ||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | =cut | ||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | subtype XSDgMonth, as Int, where { $_[0] > 0 && $_[0] < 13 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | =head2 XSDgDay | ||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | subtype XSDgDay, as Int, where { $_[0] > 0 && $_[0] < 32 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | =head2 XSDBool | ||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||
| 201 | 1 | subtype XSDBool, as Bool; | |||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | coerce XSDBool, from Undef, via { 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | coerce XSDBool, from Str, via { return ($_[0] =~ /(1|true|on|yes)/i) ? 1 : 0 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | =head2 Currency | ||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||
| 209 | 1 | subtype Currency, as Num; | |||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | coerce Currency, from Num, via { my $x = int($_[0] * 100); return $x/100 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | =head2 Decimal3 | ||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | 1 | subtype Decimal3, as Num; | |||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | coerce Decimal3, from Num, via { my $x = int($_[0] * 1000); return $x/1000 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | =head2 UCToken | ||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||
| 223 | 1 | subtype UCToken, as Str; | |||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | coerce UCToken, from Str, via { uc shift }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||
| 226 | =head2 LCToken | ||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||
| 228 | =cut | ||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||
| 230 | 1 | subtype LCToken, as Str; | |||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | coerce LCToken, from Str, via { lc shift }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||
| 233 | =head2 Set | ||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||
| 235 | =cut | ||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||
| 237 | 1 | class_type Set, { class => 'Set::Scalar' }; | |||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||
| 239 | =head2 IntSet | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | =cut | ||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||
| 243 | 1 | subtype IntSet, as Set; | |||||||||||||||||||||||||||||||||||
| 244 | coerce IntSet, from ArrayRef[Str], | ||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | via { Set::Scalar->new(map { int $_ } @{$_[0]}) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||
| 247 | =head2 TokenSet | ||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||
| 251 | 1 | subtype TokenSet, as Set; | |||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | coerce TokenSet, from ArrayRef[Str], via { Set::Scalar->new(@{$_[0]}) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||
| 254 | =head2 NumberRange | ||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | =cut | ||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||
| 258 | 1 | class_type NumberRange, { class => 'Set::Infinite' }; | |||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub _coerce_number_range { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_number_range: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($s, $e) = @{ref $_[0] eq 'ARRAY' ? $_[0] : [$_[0]]}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 262 | #warn "hi i'm here"; | ||||||||||||||||||||||||||||||||||||
| 263 | #warn defined $e; | ||||||||||||||||||||||||||||||||||||
| 264 | #require Data::Dumper; | ||||||||||||||||||||||||||||||||||||
| 265 | #warn Data::Dumper::Dumper | ||||||||||||||||||||||||||||||||||||
| 266 | 0 | my ($ds, $de) = (defined $s, defined $e); | |||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if (!$ds and !$de) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$ds || $de
MC/DC0%0/2
$ds || $de
$ds
$de
Truth table0%0/3
A || B
A= $dsB= $de
| |||||||||||||||||||||||||||||||||||||
| 268 | 0 | ($s, $e) = (NEG_INF, INF); | |||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||
| 270 | elsif (!$ds) { | ||||||||||||||||||||||||||||||||||||
| 271 | 0 | $s = NEG_INF; | |||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||
| 273 | elsif (!$de) { | ||||||||||||||||||||||||||||||||||||
| 274 | 0 | $e = INF; | |||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||||||||||
| 277 | 0 | ($s, $e) = sort { $a <=> $b } map { $_ + 0 } ($s, $e); | |||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||
| 280 | 0 | Set::Infinite->new($s, $e); | |||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | 1 | coerce NumberRange, from Num, via \&_coerce_number_range; | |||||||||||||||||||||||||||||||||||
| 284 | 1 | coerce NumberRange, from ArrayRef[Maybe[Num]], via \&_coerce_number_range; | |||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||
| 286 | =head2 DateRange | ||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | =cut | ||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||
| 290 | 1 | class_type DateSpan, { class => 'DateTime::Span' }; | |||||||||||||||||||||||||||||||||||
| 291 | 1 | class_type DateSpanSet, { class => 'DateTime::SpanSet' }; | |||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||
| 293 | #union DateRange, [DateSpan, DateSpanSet]; | ||||||||||||||||||||||||||||||||||||
| 294 | 1 | subtype DateRange, as DateSpan|DateSpanSet; | |||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub _make_date_span { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_make_date_span: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||
| 297 | 0 | my ($d1, $d2) = @_; | |||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | $d1 = defined $d1 ? ref $d1 ? $d1 : _make_date(split /-/, $d1) : | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 299 | DateTime::Infinite::Past->new; | ||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | $d2 = defined $d2 ? ref $d2 ? $d2 : _make_date(split /-/, $d2) : | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 301 | DateTime::Infinite::Future->new; | ||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||
| 303 | 0 | my %p; | |||||||||||||||||||||||||||||||||||
| 304 | 0 | @p{qw(start end)} = sort { $a <=> $b } ($d1, $d2); | |||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||
| 306 | 0 | DateTime::Span->from_datetimes(%p); | |||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||
| 309 | coerce DateRange, from ArrayRef[Maybe[Str]], | ||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | via { _make_date_span(@{$_[0]}) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||
| 312 | coerce DateRange, from ArrayRef[Maybe[XSDdate]], | ||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | via { _make_date_span(@{$_[0]}) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||
| 315 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | Dorian Taylor, C<< <dorian at cpan.org> >> | ||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||
| 321 | Copyright 2013 Dorian Taylor. | ||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||
| 323 | Licensed under the Apache License, Version 2.0 (the "License"); you | ||||||||||||||||||||||||||||||||||||
| 324 | may not use this file except in compliance with the License. You may | ||||||||||||||||||||||||||||||||||||
| 325 | obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||
| 326 | L<http://www.apache.org/licenses/LICENSE-2.0> . | ||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||
| 328 | Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||
| 329 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||
| 330 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||||||||||||||||||||||||||||||||||
| 331 | implied. See the License for the specific language governing | ||||||||||||||||||||||||||||||||||||
| 332 | permissions and limitations under the License. | ||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||
| 334 | =cut | ||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||
| 336 | 1 | 1; # End of Params::Registry::Types | |||||||||||||||||||||||||||||||||||