line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
382623
|
use 5.006001; |
|
5
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
240
|
|
2
|
5
|
|
|
5
|
|
34
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
191
|
|
3
|
5
|
|
|
5
|
|
43
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
641
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Types::LoadableClass; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Type::Library |
11
|
5
|
|
|
|
|
68
|
-base, |
12
|
|
|
|
|
|
|
-declare => qw( |
13
|
|
|
|
|
|
|
ModuleName LoadableClass LoadableRole |
14
|
|
|
|
|
|
|
ClassIsa ClassDoes ClassCan |
15
|
5
|
|
|
5
|
|
5751
|
); |
|
5
|
|
|
|
|
182768
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
18506
|
use Type::Utils -all; |
|
5
|
|
|
|
|
36645
|
|
|
5
|
|
|
|
|
69
|
|
18
|
5
|
|
|
5
|
|
32283
|
use Types::Standard qw( StrMatch RoleName ); |
|
5
|
|
|
|
|
275109
|
|
|
5
|
|
|
|
|
82
|
|
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
9001
|
use Module::Runtime qw($module_name_rx is_module_name); |
|
5
|
|
|
|
|
5662
|
|
|
5
|
|
|
|
|
41
|
|
21
|
5
|
|
|
5
|
|
200107
|
use Class::Load qw(load_optional_class is_class_loaded); |
|
5
|
|
|
|
|
417709
|
|
|
5
|
|
|
|
|
5438
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
declare ModuleName, |
24
|
|
|
|
|
|
|
as StrMatch[ qr/\A$module_name_rx\z/ ], |
25
|
|
|
|
|
|
|
message { |
26
|
|
|
|
|
|
|
"'$_' is not a valid module name"; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
declare LoadableClass, |
30
|
|
|
|
|
|
|
as ModuleName, |
31
|
|
|
|
|
|
|
where { |
32
|
|
|
|
|
|
|
load_optional_class($_) |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
inline_as { |
35
|
|
|
|
|
|
|
(undef, "Class::Load::load_optional_class($_)"); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
message { |
38
|
|
|
|
|
|
|
ModuleName->validate($_) or "'$_' could not be loaded"; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
declare LoadableRole, |
42
|
|
|
|
|
|
|
as intersection([ LoadableClass, RoleName ]), |
43
|
|
|
|
|
|
|
message { |
44
|
|
|
|
|
|
|
LoadableClass->validate($_) or "'$_' is not a loadable role"; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
declare ClassIsa, |
48
|
|
|
|
|
|
|
as LoadableClass, |
49
|
|
|
|
|
|
|
constraint_generator => sub { |
50
|
|
|
|
|
|
|
my @bases = @_ or return ClassIsa; |
51
|
|
|
|
|
|
|
return sub { |
52
|
|
|
|
|
|
|
$_[0]->isa($_) && return !!1 for @bases; |
53
|
|
|
|
|
|
|
return !!0; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
inline_generator => sub { |
57
|
|
|
|
|
|
|
my @bases = @_; |
58
|
|
|
|
|
|
|
return sub { |
59
|
|
|
|
|
|
|
my $var = $_[1]; |
60
|
|
|
|
|
|
|
return ( |
61
|
|
|
|
|
|
|
undef, |
62
|
|
|
|
|
|
|
sprintf( |
63
|
|
|
|
|
|
|
'(%s)', |
64
|
|
|
|
|
|
|
join( |
65
|
|
|
|
|
|
|
' or ', |
66
|
|
|
|
|
|
|
map(sprintf('%s->isa(%s)', $var, B::perlstring($_)), @bases), |
67
|
|
|
|
|
|
|
), |
68
|
|
|
|
|
|
|
), |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
declare ClassDoes, |
74
|
|
|
|
|
|
|
as LoadableClass, |
75
|
|
|
|
|
|
|
constraint_generator => sub { |
76
|
|
|
|
|
|
|
my @roles = @_ or return ClassDoes; |
77
|
|
|
|
|
|
|
return sub { |
78
|
|
|
|
|
|
|
$_[0]->DOES($_) || return !!0 for @roles; |
79
|
|
|
|
|
|
|
return !!1; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
inline_generator => sub { |
83
|
|
|
|
|
|
|
my @roles = @_; |
84
|
|
|
|
|
|
|
return sub { |
85
|
|
|
|
|
|
|
my $var = $_[1]; |
86
|
|
|
|
|
|
|
return ( |
87
|
|
|
|
|
|
|
undef, |
88
|
|
|
|
|
|
|
sprintf( |
89
|
|
|
|
|
|
|
'do { my $method = %s->can("DOES")||%s->can("isa"); %s } ', |
90
|
|
|
|
|
|
|
$var, |
91
|
|
|
|
|
|
|
$var, |
92
|
|
|
|
|
|
|
join( |
93
|
|
|
|
|
|
|
' and ', |
94
|
|
|
|
|
|
|
map(sprintf('%s->$method(%s)', $var, B::perlstring($_)), @roles), |
95
|
|
|
|
|
|
|
), |
96
|
|
|
|
|
|
|
), |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
declare ClassCan, |
102
|
|
|
|
|
|
|
as LoadableClass, |
103
|
|
|
|
|
|
|
constraint_generator => sub { |
104
|
|
|
|
|
|
|
my @methods = @_ or return ClassCan; |
105
|
|
|
|
|
|
|
return sub { |
106
|
|
|
|
|
|
|
$_[0]->can($_) || return !!0 for @methods; |
107
|
|
|
|
|
|
|
return !!1; |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
inline_generator => sub { |
111
|
|
|
|
|
|
|
my @methods = @_; |
112
|
|
|
|
|
|
|
return sub { |
113
|
|
|
|
|
|
|
my $var = $_[1]; |
114
|
|
|
|
|
|
|
return ( |
115
|
|
|
|
|
|
|
undef, |
116
|
|
|
|
|
|
|
map(sprintf('%s->can(%s)', $var, B::perlstring($_)), @methods), |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__PACKAGE__->meta->add_coercion({ |
122
|
|
|
|
|
|
|
name => 'ExpandPrefix', |
123
|
|
|
|
|
|
|
type_constraint => ModuleName, |
124
|
|
|
|
|
|
|
coercion_generator => sub { |
125
|
|
|
|
|
|
|
my ($self, $target, $prefix) = @_; |
126
|
|
|
|
|
|
|
Types::TypeTiny::StringLike->assert_valid($prefix); |
127
|
|
|
|
|
|
|
return ( |
128
|
|
|
|
|
|
|
StrMatch[qr{\A-.+}], |
129
|
|
|
|
|
|
|
qq{ do { (my \$tmp = \$_) =~ s{\\A-}{$prefix\::}; \$tmp } }, |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
}); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |