line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
18
|
|
|
18
|
|
23700
|
use warnings; |
|
18
|
|
|
|
|
32
|
|
|
18
|
|
|
|
|
774
|
|
2
|
18
|
|
|
18
|
|
89
|
use strict; |
|
18
|
|
|
|
|
24
|
|
|
18
|
|
|
|
|
1025
|
|
3
|
|
|
|
|
|
|
package MooseX::Types::Util; |
4
|
|
|
|
|
|
|
# ABSTRACT: Common utility functions for the distribution |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.50'; |
7
|
|
|
|
|
|
|
|
8
|
18
|
|
|
18
|
|
92
|
use Scalar::Util 'blessed'; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
1314
|
|
9
|
18
|
|
|
18
|
|
88
|
use base 'Exporter'; |
|
18
|
|
|
|
|
26
|
|
|
18
|
|
|
|
|
1729
|
|
10
|
18
|
|
|
18
|
|
635
|
use namespace::autoclean; |
|
18
|
|
|
|
|
29505
|
|
|
18
|
|
|
|
|
230
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
13
|
|
|
|
|
|
|
#pod |
14
|
|
|
|
|
|
|
#pod This package the exportable functions that many parts in |
15
|
|
|
|
|
|
|
#pod L<MooseX::Types> might need. |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod =cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw( filter_tags has_available_type_export ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#pod =head1 FUNCTIONS |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod =head2 filter_tags |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod Takes a list and returns two references. The first is a hash reference |
26
|
|
|
|
|
|
|
#pod containing the tags as keys and the number of their appearance as values. |
27
|
|
|
|
|
|
|
#pod The second is an array reference containing all other elements. |
28
|
|
|
|
|
|
|
#pod |
29
|
|
|
|
|
|
|
#pod =cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub filter_tags { |
32
|
22
|
|
|
22
|
1
|
63
|
my (@list) = @_; |
33
|
22
|
|
|
|
|
41
|
my (%tags, @other); |
34
|
22
|
|
|
|
|
62
|
for (@list) { |
35
|
63
|
50
|
|
|
|
174
|
if (/^:(.*)$/) { |
36
|
0
|
|
|
|
|
0
|
$tags{ $1 }++; |
37
|
0
|
|
|
|
|
0
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
63
|
|
|
|
|
109
|
push @other, $_; |
40
|
|
|
|
|
|
|
} |
41
|
22
|
|
|
|
|
103
|
return \%tags, \@other; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#pod =head2 has_available_type_export |
45
|
|
|
|
|
|
|
#pod |
46
|
|
|
|
|
|
|
#pod TypeConstraint | Undef = has_available_type_export($package, $name); |
47
|
|
|
|
|
|
|
#pod |
48
|
|
|
|
|
|
|
#pod This function allows you to introspect if a given type export is available |
49
|
|
|
|
|
|
|
#pod I<at this point in time>. This means that the C<$package> must have imported |
50
|
|
|
|
|
|
|
#pod a type constraint with the name C<$name>, and it must be still in its symbol |
51
|
|
|
|
|
|
|
#pod table. |
52
|
|
|
|
|
|
|
#pod |
53
|
|
|
|
|
|
|
#pod Two arguments are expected: |
54
|
|
|
|
|
|
|
#pod |
55
|
|
|
|
|
|
|
#pod =over 4 |
56
|
|
|
|
|
|
|
#pod |
57
|
|
|
|
|
|
|
#pod =item $package |
58
|
|
|
|
|
|
|
#pod |
59
|
|
|
|
|
|
|
#pod The name of the package to introspect. |
60
|
|
|
|
|
|
|
#pod |
61
|
|
|
|
|
|
|
#pod =item $name |
62
|
|
|
|
|
|
|
#pod |
63
|
|
|
|
|
|
|
#pod The name of the type export to introspect. |
64
|
|
|
|
|
|
|
#pod |
65
|
|
|
|
|
|
|
#pod =back |
66
|
|
|
|
|
|
|
#pod |
67
|
|
|
|
|
|
|
#pod B<Note> that the C<$name> is the I<exported> name of the type, not the declared |
68
|
|
|
|
|
|
|
#pod one. This means that if you use L<Sub::Exporter>s functionality to rename an import |
69
|
|
|
|
|
|
|
#pod like this: |
70
|
|
|
|
|
|
|
#pod |
71
|
|
|
|
|
|
|
#pod use MyTypes Str => { -as => 'MyStr' }; |
72
|
|
|
|
|
|
|
#pod |
73
|
|
|
|
|
|
|
#pod you would have to introspect this type like this: |
74
|
|
|
|
|
|
|
#pod |
75
|
|
|
|
|
|
|
#pod has_available_type_export $package, 'MyStr'; |
76
|
|
|
|
|
|
|
#pod |
77
|
|
|
|
|
|
|
#pod The return value will be either the type constraint that belongs to the export |
78
|
|
|
|
|
|
|
#pod or an undefined value. |
79
|
|
|
|
|
|
|
#pod |
80
|
|
|
|
|
|
|
#pod =cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub has_available_type_export { |
83
|
13
|
|
|
13
|
1
|
3431
|
my ($package, $name) = @_; |
84
|
|
|
|
|
|
|
|
85
|
13
|
100
|
|
|
|
84
|
my $sub = $package->can($name) |
86
|
|
|
|
|
|
|
or return undef; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return undef |
89
|
5
|
100
|
66
|
|
|
49
|
unless blessed $sub && $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT'); |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
12
|
return $sub->(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
95
|
|
|
|
|
|
|
#pod |
96
|
|
|
|
|
|
|
#pod L<MooseX::Types::Moose>, L<Exporter> |
97
|
|
|
|
|
|
|
#pod |
98
|
|
|
|
|
|
|
#pod =cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=pod |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=encoding UTF-8 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
MooseX::Types::Util - Common utility functions for the distribution |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 0.50 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 DESCRIPTION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This package the exportable functions that many parts in |
119
|
|
|
|
|
|
|
L<MooseX::Types> might need. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 FUNCTIONS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 filter_tags |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Takes a list and returns two references. The first is a hash reference |
126
|
|
|
|
|
|
|
containing the tags as keys and the number of their appearance as values. |
127
|
|
|
|
|
|
|
The second is an array reference containing all other elements. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 has_available_type_export |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
TypeConstraint | Undef = has_available_type_export($package, $name); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This function allows you to introspect if a given type export is available |
134
|
|
|
|
|
|
|
I<at this point in time>. This means that the C<$package> must have imported |
135
|
|
|
|
|
|
|
a type constraint with the name C<$name>, and it must be still in its symbol |
136
|
|
|
|
|
|
|
table. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Two arguments are expected: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 4 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item $package |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The name of the package to introspect. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item $name |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The name of the type export to introspect. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
B<Note> that the C<$name> is the I<exported> name of the type, not the declared |
153
|
|
|
|
|
|
|
one. This means that if you use L<Sub::Exporter>s functionality to rename an import |
154
|
|
|
|
|
|
|
like this: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
use MyTypes Str => { -as => 'MyStr' }; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
you would have to introspect this type like this: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
has_available_type_export $package, 'MyStr'; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The return value will be either the type constraint that belongs to the export |
163
|
|
|
|
|
|
|
or an undefined value. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<MooseX::Types::Moose>, L<Exporter> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 SUPPORT |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types> |
172
|
|
|
|
|
|
|
(or L<bug-MooseX-Types@rt.cpan.org|mailto:bug-MooseX-Types@rt.cpan.org>). |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
175
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
178
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHOR |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Robert "phaylon" Sedlacek <rs@474.at> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Robert "phaylon" Sedlacek. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
189
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |