Types/UndefinedType.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 100% 3 / 3 totaltotal 90.4% 57 / 63 CC 5 SCAR 5.2
CC
5
Cov
89%
__autovivify
3.0
can_be_inlined
2.1
AUTOLOAD
2.1
CRAP 1.7
« Types/CheckedUtilExports.pm ↑ Summary Types/Moose.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::UndefinedType;
4 # ABSTRACT: a fallback type for when a type cannot be found
5  
6 17 our $VERSION = '0.51';
7  
8 17 ▶use Moose::Util::TypeConstraints ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Carp::Clan '^MooseX::Types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use namespace::autoclean 0.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 52 ▶use overload '""' => sub { shift->name },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13 17 fallback => 1;
14  
15 #pod =head1 DESCRIPTION
16 #pod
17 #pod Whenever a type handle function (e.g. C<Int()> can't find a type
18 #pod constraint under its full name, it assumes it has not yet been defined.
19 #pod It will then return an instance of this class, handling only
20 #pod stringification, name and possible identification of undefined types.
21 #pod
22 #pod Later, when you try to use the Undefined Type Constraint, autovivification will
23 #pod be attempted.
24 #pod
25 #pod =head1 METHODS
26 #pod
27 #pod =head2 new
28 #pod
29 #pod Takes a full type name as argument and returns an instance of this
30 #pod class.
31 #pod
32 #pod =cut
33  
34 52 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
35 52 return bless { name => $_[1] }, $_[0];
36 }
37  
38 #pod =head2 name
39 #pod
40 #pod Returns the stored type name.
41 #pod
42 #pod =cut
43  
44 204 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
45 204 return $_[0]->{name};
46 }
47  
48 #pod =head2 __autovivify
49 #pod
50 #pod Try to see if the type constraint has yet been defined and if so create it.
51 #pod
52 #pod =cut
53  
54 9 ▶sub __autovivify {
Subroutine __autovivify: called CC=3 SCAR=11.0
55 9 my ($self) = @_;
56 9 ▶ if(my $tc = $self->{instance}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $tc = $self->{'instance'}) { } 6 3 9
elsif (my $new_tc = Moose::Util::TypeConstraints::find_type_constraint($self->name)) { } 1 2 3
57 6 return $tc;
58 } elsif( my $new_tc = Moose::Util::TypeConstraints::find_type_constraint($self->name)) {
59 1 $self->{instance} = $new_tc;
60 1 return $new_tc;
61 } else {
62 2 return;
63 }
64 }
65  
66 #pod =head2 can_be_inlined
67 #pod
68 #pod Make sure that if a type hasn't been defined yet when Moose wants to inline it,
69 #pod we don't allow inlining.
70 #pod
71 #pod =cut
72  
73 2 ▶sub can_be_inlined {
Subroutine can_be_inlined: called CC=2 SCAR=7.6
Pod documented
74 2 my $self = shift;
75 2 ▶ if(my $type_constraint = $self->__autovivify) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type_constraint = $self->__autovivify) { } 0 2 2
76 0 return $type_constraint->can_be_inlined;
77 } else {
78 2 return;
79 }
80 }
81  
82 #pod =head2 AUTOLOAD
83 #pod
84 #pod Try to autovivify and delegate
85 #pod
86 #pod =cut
87  
88 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=7.4
89 7 my ($self, @args) = @_;
90 7 my ($method) = our $AUTOLOAD =~ /([^:]+)$/;
91  
92 7 ▶ if(my $type_constraint = $self->__autovivify) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type_constraint = $self->__autovivify) { } 7 0 7
93 7 return $type_constraint->$method(@args);
94 } else {
95 0 croak "Method '$method' is not supported for " . $self->name;
96 }
97 }
98  
99 #pod =head2 DESTROY
100 #pod
101 #pod Moose::Meta::TypeConstraint::Parameterizable complains if this isn't here. TODO
102 #pod to find out why.
103 #pod
104 #pod =cut
105  
106 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
107 0 return;
108 }
109  
110 #pod =head1 SEE ALSO
111 #pod
112 #pod L<MooseX::Types::Moose>,
113 #pod L<Moose::Util::TypeConstraints>,
114 #pod L<Moose::Meta::TypeConstraint>,
115 #pod L<Carp::Clan>
116 #pod
117 #pod =cut
118  
119  
120 17 1;
121  
122 __END__
« Types/CheckedUtilExports.pm ↑ Summary Types/Moose.pm »