line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Types::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Types related to Mojo |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
787928
|
use v5.10; |
|
5
|
|
|
|
|
36
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
132
|
|
8
|
5
|
|
|
5
|
|
37
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
249
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Type::Library |
11
|
5
|
|
|
|
|
85
|
-base, |
12
|
5
|
|
|
5
|
|
2583
|
-declare => qw( MojoCollection MojoFile MojoFileList MojoUserAgent MojoURL ); |
|
5
|
|
|
|
|
129558
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
7023
|
use Type::Utils -all; |
|
5
|
|
|
|
|
23612
|
|
|
5
|
|
|
|
|
45
|
|
15
|
5
|
|
|
5
|
|
19393
|
use Types::Standard -types; |
|
5
|
|
|
|
|
222570
|
|
|
5
|
|
|
|
|
69
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
24128
|
use Carp; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
320
|
|
18
|
5
|
|
|
5
|
|
2336
|
use Mojo::File; |
|
5
|
|
|
|
|
973569
|
|
|
5
|
|
|
|
|
253
|
|
19
|
5
|
|
|
5
|
|
47
|
use Mojo::Collection; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
151
|
|
20
|
5
|
|
|
5
|
|
2273
|
use Mojo::URL; |
|
5
|
|
|
|
|
36743
|
|
|
5
|
|
|
|
|
39
|
|
21
|
5
|
|
|
5
|
|
214
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
4225
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$meta->add_type( |
28
|
|
|
|
|
|
|
name => 'MojoCollection', |
29
|
|
|
|
|
|
|
parent => InstanceOf['Mojo::Collection'], |
30
|
|
|
|
|
|
|
constraint_generator => sub { |
31
|
|
|
|
|
|
|
return $meta->get_type('MojoCollection') if !@_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $check = $_[0] // ''; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
croak "Parameter to MojoCollection[`a] expected to be a type constraint; got $check" |
36
|
|
|
|
|
|
|
if !blessed $check || !$check->isa('Type::Tiny'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return sub { |
39
|
|
|
|
|
|
|
return if !blessed $_ and $_->isa('Mojo::Collection'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $fail = $_->first( sub { |
42
|
|
|
|
|
|
|
!$check->( $_ ); |
43
|
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
!$fail; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
coercion_generator => sub { |
49
|
|
|
|
|
|
|
my ($parent, $child, $param) = @_; |
50
|
|
|
|
|
|
|
return $parent->coercion; |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
#inline_generator => sub {}, |
53
|
|
|
|
|
|
|
#deep_explanation => sub {}, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
coerce MojoCollection, |
57
|
|
|
|
|
|
|
from ArrayRef, via { Mojo::Collection->new( @{$_} ) } |
58
|
|
|
|
|
|
|
; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
class_type MojoUserAgent, { class => 'Mojo::UserAgent' }; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
class_type MojoFile, { class => 'Mojo::File' }; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
coerce MojoFile, |
65
|
|
|
|
|
|
|
from Str, via { Mojo::File->new( $_ ) } |
66
|
|
|
|
|
|
|
; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
declare MojoFileList, |
69
|
|
|
|
|
|
|
as MojoCollection[MojoFile]; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
coerce MojoFileList, |
72
|
|
|
|
|
|
|
from MojoCollection[Str], |
73
|
|
|
|
|
|
|
via { |
74
|
|
|
|
|
|
|
my $new = $_->map( sub { Mojo::File->new($_) } ); |
75
|
|
|
|
|
|
|
$new; |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
from ArrayRef[Str], |
78
|
|
|
|
|
|
|
via { |
79
|
|
|
|
|
|
|
my @list = @{$_}; |
80
|
|
|
|
|
|
|
Mojo::Collection->new( map{ Mojo::File->new( $_ ) } @list ); |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
from ArrayRef[MojoFile], |
83
|
|
|
|
|
|
|
via { |
84
|
|
|
|
|
|
|
Mojo::Collection->new( @{ $_ } ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$meta->add_type( |
89
|
|
|
|
|
|
|
name => 'MojoURL', |
90
|
|
|
|
|
|
|
parent => InstanceOf['Mojo::URL'], |
91
|
|
|
|
|
|
|
constraint_generator => sub { |
92
|
|
|
|
|
|
|
return $meta->get_type('MojoURL') if !@_; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $type = $_[0]; |
95
|
|
|
|
|
|
|
my ($scheme, $secure) = $type =~ m{(.*?)(s\?)?\z}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return sub { |
98
|
|
|
|
|
|
|
return if !blessed $_ and $_->isa('Mojo::URL'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return 1 if $_->scheme eq $scheme; |
101
|
|
|
|
|
|
|
return 1 if $secure && $_->scheme eq $scheme . 's'; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
coercion_generator => sub { |
107
|
|
|
|
|
|
|
my ($parent, $child, $param) = @_; |
108
|
|
|
|
|
|
|
return $parent->coercion; |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
coerce MojoURL, |
113
|
|
|
|
|
|
|
from Str, via { Mojo::URL->new( $_ ) } |
114
|
|
|
|
|
|
|
; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
coerce MojoCollection, |
117
|
|
|
|
|
|
|
from ArrayRef, via { Mojo::Collection->new( @{$_} ) } |
118
|
|
|
|
|
|
|
; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |