File Coverage

/tmp/W74rLRJ5T6.mite.pm
Criterion Covered Total %
statement 76 97 78.3
branch 21 44 47.7
condition 6 27 22.2
subroutine 15 16 93.7
pod n/a
total 118 184 64.1


line stmt bran cond sub pod time code
1             {
2             package MyPerson;
3 1     1   8 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         4  
  1         28  
5 1     1   5 no warnings qw( once void );
  1         2  
  1         141  
6              
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Mite::Shim";
9             our $MITE_VERSION = "0.012000";
10             # Mite keywords
11             BEGIN {
12 1     1   4 my ( $SHIM, $CALLER ) = ( "Mite::Shim", "MyPerson" );
13 1         3 ( *after, *around, *before, *extends, *has, *signature_for, *with ) = do {
14             package Mite::Shim;
15 1     1   7 no warnings 'redefine';
  1         2  
  1         201  
16             (
17 0         0 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
18 0         0 sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
19 0         0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
20             sub {},
21 4         14 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
22 0         0 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
23 0         0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
24 1         46 );
25             };
26             };
27              
28             # Gather metadata for constructor and destructor
29             sub __META__ {
30 1     1   15 no strict 'refs';
  1         2  
  1         905  
31 1   33 1   2 my $class = shift; $class = ref($class) || $class;
  1         7  
32 1         5 my $linear_isa = mro::get_linear_isa( $class );
33             return {
34             BUILD => [
35 1 50       33 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         10  
  0         0  
36 1         4 map { "$_\::BUILD" } reverse @$linear_isa
37             ],
38             DEMOLISH => [
39 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         19  
  0         0  
40 1         4 map { "$_\::DEMOLISH" } @$linear_isa
  1         4  
41             ],
42             HAS_BUILDARGS => $class->can('BUILDARGS'),
43             HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
44             };
45             }
46              
47              
48             # Standard Moose/Moo-style constructor
49             sub new {
50 1 50   1   176 my $class = ref($_[0]) ? ref(shift) : shift;
51 1   33     8 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
52 1         2 my $self = bless {}, $class;
53 1 50       15 my $args = $meta->{HAS_BUILDARGS} ? $class->BUILDARGS( @_ ) : { ( @_ == 1 ) ? %{$_[0]} : @_ };
  0 50       0  
54 1         4 my $no_build = delete $args->{__no_BUILD__};
55              
56             # Attribute first_name
57             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 3
58 1         2 my $args_for_first__name = {};
59 1 100       2 for ( "first_name", "given_name" ) { next unless exists $args->{$_}; $args_for_first__name->{"first_name"} = $args->{$_}; last; };
  2         6  
  1         3  
  1         2  
60 1 50       3 Mite::Shim::croak "Missing key in constructor: first_name" unless exists $args_for_first__name->{"first_name"};
61 1         5 $self->{"first_name"} = $args_for_first__name->{"first_name"};
62              
63             # Attribute last_name
64             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 7
65 1         2 my $args_for_last__name = {};
66 1 100       3 for ( "last_name", "family_name", "surname" ) { next unless exists $args->{$_}; $args_for_last__name->{"last_name"} = $args->{$_}; last; };
  3         6  
  1         2  
  1         2  
67 1 50       6 Mite::Shim::croak "Missing key in constructor: last_name" unless exists $args_for_last__name->{"last_name"};
68 1         2 $self->{"last_name"} = $args_for_last__name->{"last_name"};
69              
70             # Attribute age
71             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 11
72 1 50       2 if ( exists $args->{"age"} ) { $self->{"age"} = $args->{"age"}; } ;
  0         0  
73              
74             # Attribute height
75             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 14
76 1 50       3 if ( exists $args->{"height"} ) { $self->{"height"} = $args->{"height"}; } ;
  0         0  
77              
78              
79             # Call BUILD methods
80 1 50 33     4 $self->BUILDALL( $args ) if ( ! $no_build and @{ $meta->{BUILD} || [] } );
  1 50       7  
81              
82             # Unrecognized parameters
83 1 50       2 my @unknown = grep not( /\A(?:age|f(?:amily_name|irst_name)|given_name|height|last_name|surname)\z/ ), keys %{$args}; @unknown and Mite::Shim::croak( "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
  1         10  
  1         3  
84              
85 1         6 return $self;
86             }
87              
88             # Used by constructor to call BUILD methods
89             sub BUILDALL {
90 0     0   0 my $class = ref( $_[0] );
91 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
92 0 0       0 $_->( @_ ) for @{ $meta->{BUILD} || [] };
  0         0  
93             }
94              
95             # Destructor should call DEMOLISH methods
96             sub DESTROY {
97 1     1   808 my $self = shift;
98 1   33     19 my $class = ref( $self ) || $self;
99 1   33     4 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
100 1 50       6 my $in_global_destruction = defined ${^GLOBAL_PHASE}
101             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
102             : Devel::GlobalDestruction::in_global_destruction();
103 1 50       3 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  1         4  
104 0         0 my $e = do {
105 0         0 local ( $?, $@ );
106 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
107 0         0 $@;
108             };
109 1     1   8 no warnings 'misc'; # avoid (in cleanup) warnings
  1         2  
  1         711  
110 0 0       0 die $e if $e; # rethrow
111             }
112 1         10 return;
113             }
114              
115             my $__XS = !$ENV{PERL_ONLY} && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
116              
117             # Accessors for age
118             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 11
119             if ( $__XS ) {
120             Class::XSAccessor->import(
121             chained => 1,
122             "getters" => { "age" => "age" },
123             );
124             }
125             else {
126             *age = sub { @_ == 1 or Mite::Shim::croak( 'Reader "age" usage: $self->age()' ); $_[0]{"age"} };
127             }
128              
129             # Accessors for first_name
130             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 3
131             if ( $__XS ) {
132             Class::XSAccessor->import(
133             chained => 1,
134             "accessors" => { "first_name" => "first_name" },
135             );
136             }
137             else {
138             *first_name = sub { @_ > 1 ? do { $_[0]{"first_name"} = $_[1]; $_[0]; } : ( $_[0]{"first_name"} ) };
139             }
140              
141             # Aliases for first_name
142             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 3
143 2     2   1864 sub given_name { shift->first_name( @_ ) }
144              
145             # Accessors for height
146             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 14
147             if ( $__XS ) {
148             Class::XSAccessor->import(
149             chained => 1,
150             "getters" => { "height" => "height" },
151             );
152             }
153             else {
154             *height = sub { @_ == 1 or Mite::Shim::croak( 'Reader "height" usage: $self->height()' ); $_[0]{"height"} };
155             }
156              
157             # Accessors for last_name
158             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 7
159             if ( $__XS ) {
160             Class::XSAccessor->import(
161             chained => 1,
162             "getters" => { "last_name" => "last_name" },
163             "setters" => { "_set_last_name" => "last_name" },
164             );
165             }
166             else {
167             *last_name = sub { @_ == 1 or Mite::Shim::croak( 'Reader "last_name" usage: $self->last_name()' ); $_[0]{"last_name"} };
168             *_set_last_name = sub { @_ == 2 or Mite::Shim::croak( 'Writer "_set_last_name" usage: $self->_set_last_name( $newvalue )' ); $_[0]{"last_name"} = $_[1]; $_[0]; };
169             }
170              
171             # Aliases for last_name
172             # has declaration, file ../../../../tmp/W74rLRJ5T6, line 7
173 1     1   7 sub family_name { shift->last_name( @_ ) }
174 1     1   79 sub surname { shift->last_name( @_ ) }
175              
176              
177             # See UNIVERSAL
178             sub DOES {
179 7     7   11 my ( $self, $role ) = @_;
180 7         10 our %DOES;
181 7 50       14 return $DOES{$role} if exists $DOES{$role};
182 7 50       12 return 1 if $role eq __PACKAGE__;
183 7 50 0     15 if ( $INC{'Moose/Util.pm'} and my $meta = Moose::Util::find_meta( ref $self or $self ) ) {
      33        
184 0 0 0     0 $meta->can( 'does_role' ) and $meta->does_role( $role ) and return 1;
185             }
186 7         39 return $self->SUPER::DOES( $role );
187             }
188              
189             # Alias for Moose/Moo-compatibility
190             sub does {
191 7     7   2190 shift->DOES( @_ );
192             }
193              
194             1;
195             }