line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Types::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Types related to Mojo |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
817420
|
use v5.10; |
|
5
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
132
|
|
8
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
292
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Type::Library |
11
|
5
|
|
|
|
|
57
|
-base, |
12
|
5
|
|
|
5
|
|
2433
|
-declare => qw( MojoCollection MojoFile MojoFileList MojoUserAgent MojoURL ); |
|
5
|
|
|
|
|
134355
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
7200
|
use Type::Utils -all; |
|
5
|
|
|
|
|
24520
|
|
|
5
|
|
|
|
|
52
|
|
15
|
5
|
|
|
5
|
|
19260
|
use Types::Standard -types; |
|
5
|
|
|
|
|
228507
|
|
|
5
|
|
|
|
|
84
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
27294
|
use Mojo::File; |
|
5
|
|
|
|
|
1006170
|
|
|
5
|
|
|
|
|
294
|
|
18
|
5
|
|
|
5
|
|
49
|
use Mojo::Collection; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
160
|
|
19
|
5
|
|
|
5
|
|
2402
|
use Mojo::URL; |
|
5
|
|
|
|
|
38252
|
|
|
5
|
|
|
|
|
44
|
|
20
|
5
|
|
|
5
|
|
227
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
301
|
|
21
|
5
|
|
|
5
|
|
33
|
use List::Util qw(first); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
4413
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Type::Utils::extends(qw/Types::Standard/); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = 0.04; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$meta->add_type( |
30
|
|
|
|
|
|
|
name => 'MojoCollection', |
31
|
|
|
|
|
|
|
parent => InstanceOf['Mojo::Collection'], |
32
|
|
|
|
|
|
|
constraint_generator => sub { |
33
|
|
|
|
|
|
|
return $meta->get_type('MojoCollection') if !@_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $type = $_[0]; |
36
|
|
|
|
|
|
|
my $check = $meta->get_type( $_[0] ); |
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__ |