line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Types::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Types related to Mojo |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
681740
|
use v5.10; |
|
5
|
|
|
|
|
28
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
20
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
91
|
|
8
|
5
|
|
|
5
|
|
19
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
290
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Type::Library |
13
|
5
|
|
|
|
|
49
|
-base, |
14
|
5
|
|
|
5
|
|
2049
|
-declare => qw( MojoCollection MojoFile MojoFileList MojoUserAgent MojoURL ); |
|
5
|
|
|
|
|
149075
|
|
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
6755
|
use Type::Utils -all; |
|
5
|
|
|
|
|
37998
|
|
|
5
|
|
|
|
|
40
|
|
17
|
5
|
|
|
5
|
|
13461
|
use Types::Standard -types; |
|
5
|
|
|
|
|
290693
|
|
|
5
|
|
|
|
|
75
|
|
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
5
|
|
33186
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
325
|
|
20
|
5
|
|
|
5
|
|
2124
|
use Mojo::File; |
|
5
|
|
|
|
|
862400
|
|
|
5
|
|
|
|
|
229
|
|
21
|
5
|
|
|
5
|
|
36
|
use Mojo::Collection; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
123
|
|
22
|
5
|
|
|
5
|
|
2001
|
use Mojo::URL; |
|
5
|
|
|
|
|
40340
|
|
|
5
|
|
|
|
|
30
|
|
23
|
5
|
|
|
5
|
|
209
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
3434
|
|
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
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |