blib/lib/Types/Mojo.pm

filter: Statementstmt 96.1% 75 / 78 Branchbran 71.4% 10 / 14 Conditioncond 50.0% 7 / 14 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 92.0% 23 / 25 Podpod n/a totaltotal 83.5% 117 / 140 CC 13 SCAR 10.3
CC
13
Cov
87%
__ANON__
6.6
__ANON__
5.5
__ANON__
3.3
CRAP 2.8
↑ Summary
1 package Types::Mojo;
2  
3 # ABSTRACT: Types related to Mojo
4  
5 5 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION = '0.06'; # VERSION
11  
12 use Type::Library
13 5 ▶ -base,
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 -declare => qw( MojoCollection MojoFile MojoFileList MojoUserAgent MojoURL );
15  
16 5 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Mojo::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use Mojo::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 my $meta = __PACKAGE__->meta;
26  
27 $meta->add_type(
28 name => 'MojoCollection',
29 parent => InstanceOf['Mojo::Collection'],
30 22 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=5 SCAR=17.1
31 22 ▶ return $meta->get_type('MojoCollection') if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 22 22
32  
33 22 ▶ my $check = $_[0] // '';
Condition50%1/2
$_[0] // ""
l!l
220
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
34  
35 22 ▶ croak "Parameter to MojoCollection[`a] expected to be a type constraint; got $check"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($check) and $check->isa("Type::Tiny") 1 21 22
Condition66%2/3
builtin::blessed($check) and $check->isa("Type::Tiny")
!ll&&!rl&&r
1021
MC/DC50%1/2
builtin::blessed($check) and $check->isa("Type::Tiny")
builtin::blessed($check) $check->isa("Type::Tiny")
Truth table66%2/3
A and B
A= builtin::blessed($check)B= $check->isa("Type::Tiny")
ABresult
0X0
100
111
36 if !blessed $check || !$check->isa('Type::Tiny');
37  
38 12 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
39 12 ▶ return if !blessed $_ and $_->isa('Mojo::Collection');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($_) and $_->isa("Mojo::Collection") 0 12 12
Condition33%1/3
not builtin::blessed($_) and $_->isa("Mojo::Collection")
!ll&&!rl&&r
1200
MC/DC0%0/2
not builtin::blessed($_) and $_->isa("Mojo::Collection")
not builtin::blessed($_) $_->isa("Mojo::Collection")
Truth table33%1/3
not(A) and B
A= not builtin::blessed($_)B= $_->isa("Mojo::Collection")
ABresult
0X0
100
111
40  
41 32 ▶ my $fail = $_->first( sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 32 !$check->( $_ );
43 12 });
44  
45 7 !$fail;
46 21 };
47 },
48 10 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 10 my ($parent, $child, $param) = @_;
50 10 return $parent->coercion;
51 },
52 #inline_generator => sub {},
53 #deep_explanation => sub {},
54 5 );
55  
56 coerce MojoCollection,
57 3 ▶ from ArrayRef, via { Mojo::Collection->new( @{$_} ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
58 5 ;
59  
60 5 class_type MojoUserAgent, { class => 'Mojo::UserAgent' };
61  
62 5 class_type MojoFile, { class => 'Mojo::File' };
63  
64 coerce MojoFile,
65 1 ▶ from Str, via { Mojo::File->new( $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
66 5 ;
67  
68 5 declare MojoFileList,
69 as MojoCollection[MojoFile];
70  
71 coerce MojoFileList,
72 from MojoCollection[Str],
73 0 ▶ via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 ▶ my $new = $_->map( sub { Mojo::File->new($_) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 $new;
76 },
77 from ArrayRef[Str],
78 1 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 1 my @list = @{$_};
80 1 Mojo::Collection->new( map{ Mojo::File->new( $_ ) } @list );
81 },
82 from ArrayRef[MojoFile],
83 1 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
84 1 Mojo::Collection->new( @{ $_ } );
85 }
86 5 ;
87  
88 $meta->add_type(
89 name => 'MojoURL',
90 parent => InstanceOf['Mojo::URL'],
91 10 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
92 10 ▶ return $meta->get_type('MojoURL') if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 10 10
93  
94 10 my $type = $_[0];
95 10 my ($scheme, $secure) = $type =~ m{(.*?)(s\?)?\z};
96  
97 14 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=18.8
98 14 ▶ return if !blessed $_ and $_->isa('Mojo::URL');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($_) and $_->isa("Mojo::URL") 0 14 14
Condition33%1/3
not builtin::blessed($_) and $_->isa("Mojo::URL")
!ll&&!rl&&r
1400
MC/DC0%0/2
not builtin::blessed($_) and $_->isa("Mojo::URL")
not builtin::blessed($_) $_->isa("Mojo::URL")
Truth table33%1/3
not(A) and B
A= not builtin::blessed($_)B= $_->isa("Mojo::URL")
ABresult
0X0
100
111
99  
100 14 ▶ return 1 if $_->scheme eq $scheme;
Branch: 1 branch
BranchTrueFalseTotal
if $_->scheme eq $scheme 3 11 14
101 11 ▶ return 1 if $secure && $_->scheme eq $scheme . 's';
Branch: 1 branch
BranchTrueFalseTotal
if $secure and $_->scheme eq $scheme . 's' 4 7 11
Condition66%2/3
$secure and $_->scheme eq $scheme . 's'
!ll&&!rl&&r
074
MC/DC50%1/2
$secure and $_->scheme eq $scheme . 's'
$secure $_->scheme eq $scheme . 's'
Truth table66%2/3
A and B
A= $secureB= $_->scheme eq $scheme . 's'
ABresult
0X0
100
111
102  
103 7 return;
104 10 };
105 },
106 10 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
107 10 my ($parent, $child, $param) = @_;
108 10 return $parent->coercion;
109 },
110 5 );
111  
112 coerce MojoURL,
113 3 ▶ from Str, via { Mojo::URL->new( $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
114 5 ;
115  
116 5 __PACKAGE__->meta->make_immutable;
117  
118 5 1;
119  
120 __END__
↑ Summary