line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MouseX::Types; |
2
|
9
|
|
|
9
|
|
177100
|
use 5.006_002; |
|
9
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
421
|
|
3
|
9
|
|
|
9
|
|
4694
|
use Mouse::Exporter; # turns on strict and warnings |
|
9
|
|
|
|
|
76811
|
|
|
9
|
|
|
|
|
64
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
5257
|
use Mouse::Util::TypeConstraints (); |
|
9
|
|
|
|
|
52381
|
|
|
9
|
|
|
|
|
456
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
17
|
|
|
17
|
|
677
|
my($class, %args) = @_; |
11
|
|
|
|
|
|
|
|
12
|
17
|
|
|
|
|
43
|
my $type_class = caller; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
{ |
15
|
9
|
|
|
9
|
|
74
|
no strict 'refs'; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1381
|
|
|
17
|
|
|
|
|
90
|
|
16
|
17
|
|
|
|
|
35
|
*{$type_class . '::import'} = \&_initialize_import; |
|
17
|
|
|
|
|
100
|
|
17
|
17
|
|
|
|
|
27
|
push @{$type_class . '::ISA'}, 'MouseX::Types::Base'; |
|
17
|
|
|
|
|
209
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
17
|
100
|
|
|
|
86
|
if(my $declare = $args{-declare}){ |
21
|
7
|
50
|
|
|
|
28
|
if(ref($declare) ne 'ARRAY'){ |
22
|
0
|
|
|
|
|
0
|
Carp::croak("You must pass an ARRAY reference to -declare"); |
23
|
|
|
|
|
|
|
} |
24
|
7
|
|
|
|
|
48
|
my $storage = $type_class->type_storage(); |
25
|
7
|
|
|
|
|
333
|
for my $name (@{ $declare }) { |
|
7
|
|
|
|
|
18
|
|
26
|
9
|
|
|
|
|
195
|
my $fq_name = $storage->{$name} = $type_class . '::' . $name; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $type = sub { |
29
|
17
|
|
|
17
|
|
5533
|
my $obj = Mouse::Util::TypeConstraints::find_type_constraint($fq_name); |
30
|
17
|
100
|
|
|
|
227
|
if($obj){ |
31
|
8
|
|
|
|
|
61
|
my $type = $type_class->_generate_type($obj); |
32
|
|
|
|
|
|
|
|
33
|
9
|
|
|
9
|
|
50
|
no strict 'refs'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
402
|
|
34
|
9
|
|
|
9
|
|
126
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
713
|
|
35
|
8
|
|
|
|
|
13
|
*{$fq_name} = $type; |
|
8
|
|
|
|
|
35
|
|
36
|
|
|
|
|
|
|
|
37
|
8
|
|
|
|
|
17
|
return &{$type}; |
|
8
|
|
|
|
|
16
|
|
38
|
|
|
|
|
|
|
} |
39
|
9
|
|
|
|
|
99
|
return $fq_name; |
40
|
9
|
|
|
|
|
43
|
}; |
41
|
|
|
|
|
|
|
|
42
|
9
|
|
|
9
|
|
40
|
no strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1635
|
|
43
|
9
|
|
|
|
|
194
|
*{$fq_name} = $type; |
|
9
|
|
|
|
|
52
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
17
|
|
|
|
|
295
|
Mouse::Util::TypeConstraints->import({ into => $type_class }); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _initialize_import { |
51
|
14
|
|
|
14
|
|
25699
|
my $type_class = $_[0]; |
52
|
|
|
|
|
|
|
|
53
|
14
|
|
|
|
|
119
|
my $storage = $type_class->type_storage; |
54
|
|
|
|
|
|
|
|
55
|
14
|
|
|
|
|
24
|
my @exporting; |
56
|
|
|
|
|
|
|
|
57
|
14
|
|
|
|
|
92
|
for my $name ($type_class->type_names) { |
58
|
196
|
|
33
|
|
|
498
|
my $fq_name = $storage->{$name} |
59
|
|
|
|
|
|
|
|| Carp::croak(qq{"$name" is not exported by $type_class}); |
60
|
|
|
|
|
|
|
|
61
|
196
|
|
33
|
|
|
493
|
my $obj = Mouse::Util::TypeConstraints::find_type_constraint($fq_name) |
62
|
|
|
|
|
|
|
|| Carp::croak(qq{"$name" is declared but not defined in $type_class}); |
63
|
|
|
|
|
|
|
|
64
|
196
|
|
|
|
|
2022
|
push @exporting, $name, 'is_' . $name; |
65
|
|
|
|
|
|
|
|
66
|
9
|
|
|
9
|
|
49
|
no strict 'refs'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
231
|
|
67
|
9
|
|
|
9
|
|
43
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
886
|
|
68
|
196
|
|
|
|
|
454
|
*{$type_class . '::' . $name} = $type_class->_generate_type($obj); |
|
196
|
|
|
|
|
870
|
|
69
|
196
|
|
|
|
|
756
|
*{$type_class . '::is_' . $name} = $obj->_compiled_type_constraint; |
|
196
|
|
|
|
|
1073
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
14
|
|
|
|
|
124
|
my($import, $unimport) = Mouse::Exporter->build_import_methods( |
73
|
|
|
|
|
|
|
exporting_package => $type_class, |
74
|
|
|
|
|
|
|
as_is => \@exporting, |
75
|
|
|
|
|
|
|
groups => { default => [] }, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
9
|
|
|
9
|
|
73
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
264
|
|
79
|
9
|
|
|
9
|
|
40
|
no strict 'refs'; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
2906
|
|
80
|
14
|
|
|
|
|
4123
|
*{$type_class . '::import'} = $import; # redefine myself! |
|
14
|
|
|
|
|
57
|
|
81
|
14
|
|
|
|
|
21
|
*{$type_class . '::unimport'} = $unimport; |
|
14
|
|
|
|
|
63
|
|
82
|
|
|
|
|
|
|
|
83
|
14
|
|
|
|
|
22
|
goto &{$import}; |
|
14
|
|
|
|
|
1490
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
package MouseX::Types::Base; |
89
|
|
|
|
|
|
|
my %storage; |
90
|
|
|
|
|
|
|
sub type_storage { # can be overriden |
91
|
17
|
|
100
|
17
|
|
705
|
return $storage{$_[0]} ||= +{} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub type_names { |
95
|
15
|
|
|
15
|
|
95
|
my($class) = @_; |
96
|
15
|
|
|
|
|
24
|
return keys %{$class->type_storage}; |
|
15
|
|
|
|
|
91
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _generate_type { |
100
|
204
|
|
|
204
|
|
265
|
my($type_class, $type_constraint) = @_; |
101
|
|
|
|
|
|
|
return sub { |
102
|
62
|
100
|
|
62
|
|
75267
|
if(@_){ # parameterization |
|
|
|
|
116
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
63
|
|
|
|
103
|
6
|
|
|
|
|
21
|
my $param = shift; |
104
|
6
|
100
|
66
|
|
|
27
|
if(!(ref($param) eq 'ARRAY' && @{$param} == 1)){ |
|
6
|
|
|
|
|
30
|
|
105
|
1
|
|
|
|
|
7
|
Carp::croak("Syntax error using type $type_constraint (you must pass an ARRAY reference of a parameter type)"); |
106
|
|
|
|
|
|
|
} |
107
|
5
|
100
|
|
|
|
11
|
if(wantarray){ |
108
|
1
|
|
|
|
|
2
|
return( $type_constraint->parameterize(@{$param}), @_ ); |
|
1
|
|
|
|
|
7
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else{ |
111
|
4
|
50
|
|
|
|
10
|
if(@_){ |
112
|
0
|
|
|
|
|
0
|
Carp::croak("Too many arguments for $type_constraint"); |
113
|
|
|
|
|
|
|
} |
114
|
4
|
|
|
|
|
4
|
return $type_constraint->parameterize(@{$param}); |
|
4
|
|
|
|
|
20
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else{ |
118
|
56
|
|
|
|
|
340
|
return $type_constraint; |
119
|
|
|
|
|
|
|
} |
120
|
204
|
|
|
|
|
1113
|
}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
__END__ |