Types/Util.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 90.0% 45 / 50 CC 6 SCAR 9.4
CC
6
Cov
90%
has_available_type_export
4.0
filter_tags
3.2
BEGIN
1.0
CRAP 2.6
« Types/Wrapper.pm ↑ Summary Types/CheckedUtilExports.pm »
1 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package MooseX::Types::Util;
4 # ABSTRACT: Common utility functions for the distribution
5  
6 17 our $VERSION = '0.51';
7  
8 17 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 17 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 20 ▶sub filter_tags {
Subroutine filter_tags: called CC=3 SCAR=11.8
Pod documented
32 20 my (@list) = @_;
33 20 my (%tags, @other);
34 20 for (@list) {
35 57 ▶ if (/^:(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^:(.*)$/) 0 57 57
36 0 $tags{ $1 }++;
37 0 next;
38 }
39 57 push @other, $_;
40 }
41 20 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 13 ▶sub has_available_type_export {
Subroutine has_available_type_export: called CC=4 SCAR=13.9
Pod documented
83 13 my ($package, $name) = @_;
84  
85 13 ▶ my $sub = $package->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $package->can($name) or return undef 5 8 13
86 or return undef;
87  
88 return undef
89 5 ▶ unless blessed $sub && $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($sub) and $sub->isa("MooseX::Types::EXPORTED_TYPE_CONSTRAINT") 1 4 5
Condition66%2/3
builtin::blessed($sub) and $sub->isa("MooseX::Types::EXPORTED_TYPE_CONSTRAINT")
!ll&&!rl&&r
104
MC/DC50%1/2
builtin::blessed($sub) and $sub->isa("MooseX::Types::EXPORTED_TYPE_CONSTRAINT")
builtin::blessed($sub) $sub->isa("MooseX::Types::EXPORTED_TYPE_CONSTRAINT")
Truth table66%2/3
A and B
A= builtin::blessed($sub)B= $sub->isa("MooseX::Types::EXPORTED_TYPE_CONSTRAINT")
ABresult
0X0
100
111
90  
91 4 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 17 1;
101  
102 __END__
« Types/Wrapper.pm ↑ Summary Types/CheckedUtilExports.pm »