File Coverage

/tmp/Y2X7vcfYXI.mite.pm
Criterion Covered Total %
statement 43 94 45.7
branch 3 36 8.3
condition 1 27 3.7
subroutine 10 14 71.4
pod n/a
total 57 171 33.3


line stmt bran cond sub pod time code
1             {
2             use strict;
3 1     1   9 use warnings;
  1         5  
  1         60  
4 1     1   6 no warnings qw( once void );
  1         6  
  1         81  
5 1     1   10  
  1         6  
  1         249  
6             our $USES_MITE = "Mite::Class";
7             our $MITE_SHIM = "Mite::Shim";
8             our $MITE_VERSION = "0.010008";
9             # Mite keywords
10             BEGIN {
11             my ( $SHIM, $CALLER ) = ( "Mite::Shim", "MyTest3" );
12 1     1   14 ( *after, *around, *before, *extends, *field, *has, *param, *signature_for, *with ) = do {
13 1         7 no warnings 'redefine';
14             (
15 1     1   6 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
  1         7  
  1         254  
16             sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
17 0         0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
18 0         0 sub {},
19 0         0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
20             sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
21 0         0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
22 0         0 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
23 0         0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
24 1         7 );
25 0         0 };
26 1         234  
27             # Mite imports
28             BEGIN {
29             require Scalar::Util;
30             *STRICT = \&Mite::Shim::STRICT;
31             *bare = \&Mite::Shim::bare;
32 1     1   11 *blessed = \&Scalar::Util::blessed;
33 1         10 *carp = \&Mite::Shim::carp;
34 1         4 *confess = \&Mite::Shim::confess;
35 1         5 *croak = \&Mite::Shim::croak;
36 1         8 *false = \&Mite::Shim::false;
37 1         7 *guard = \&Mite::Shim::guard;
38 1         11 *lazy = \&Mite::Shim::lazy;
39 1         6 *ro = \&Mite::Shim::ro;
40 1         3 *rw = \&Mite::Shim::rw;
41 1         7 *rwp = \&Mite::Shim::rwp;
42 1         4 *true = \&Mite::Shim::true;
43 1         1 };
44 1         2  
45 1         27 # Gather metadata for constructor and destructor
46             no strict 'refs';
47             my $class = shift; $class = ref($class) || $class;
48             my $linear_isa = mro::get_linear_isa( $class );
49             return {
50 1     1   5 BUILD => [
  1         6  
  1         641  
51 0   0 0   0 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  0         0  
52 0         0 map { "$_\::BUILD" } reverse @$linear_isa
53             ],
54             DEMOLISH => [
55 0 0       0 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  0         0  
  0         0  
56 0         0 map { "$_\::DEMOLISH" } @$linear_isa
57             ],
58             HAS_BUILDARGS => $class->can('BUILDARGS'),
59 0 0       0 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
  0         0  
  0         0  
60 0         0 };
  0         0  
61             }
62              
63              
64             # Standard Moose/Moo-style constructor
65             my $class = ref($_[0]) ? ref(shift) : shift;
66             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
67             my $self = bless {}, $class;
68             my $args = $meta->{HAS_BUILDARGS} ? $class->BUILDARGS( @_ ) : { ( @_ == 1 ) ? %{$_[0]} : @_ };
69             my $no_build = delete $args->{__no_BUILD__};
70 0 0   0   0  
71 0   0     0  
72 0         0  
73 0 0       0 # Call BUILD methods
  0 0       0  
74 0         0 $self->BUILDALL( $args ) if ( ! $no_build and @{ $meta->{BUILD} || [] } );
75              
76             # Unrecognized parameters
77              
78             return $self;
79 0 0 0     0 }
  0 0       0  
80              
81             # Used by constructor to call BUILD methods
82 0 0       0 my $class = ref( $_[0] );
  0 0       0  
  0 0       0  
  0         0  
  0         0  
83             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
84 0         0 $_->( @_ ) for @{ $meta->{BUILD} || [] };
85             }
86              
87             # Destructor should call DEMOLISH methods
88             my $self = shift;
89 0     0   0 my $class = ref( $self ) || $self;
90 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
91 0 0       0 my $in_global_destruction = defined ${^GLOBAL_PHASE}
  0         0  
92             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
93             : Devel::GlobalDestruction::in_global_destruction();
94             for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
95             my $e = do {
96 0     0   0 local ( $?, $@ );
97 0   0     0 eval { $demolisher->( $self, $in_global_destruction ) };
98 0   0     0 $@;
99 0 0       0 };
100             no warnings 'misc'; # avoid (in cleanup) warnings
101             die $e if $e; # rethrow
102 0 0       0 }
  0         0  
103 0         0 return;
104 0         0 }
105 0         0  
  0         0  
106 0         0  
107             # See UNIVERSAL
108 1     1   7 my ( $self, $role ) = @_;
  1         2  
  1         815  
109 0 0       0 our %DOES;
110             return $DOES{$role} if exists $DOES{$role};
111 0         0 return 1 if $role eq __PACKAGE__;
112             if ( $INC{'Moose/Util.pm'} and my $meta = Moose::Util::find_meta( ref $self or $self ) ) {
113             $meta->can( 'does_role' ) and $meta->does_role( $role ) and return 1;
114             }
115             return $self->SUPER::DOES( $role );
116             }
117 22     22   26  
118 22         18 # Alias for Moose/Moo-compatibility
119 22 50       27 shift->DOES( @_ );
120 22 50       31 }
121 22 50 0     39  
      33        
122 0 0 0     0 # Method signatures
123             our %SIGNATURE_FOR;
124 22         80  
125             $SIGNATURE_FOR{"foo"} = sub {
126             my $__NEXT__ = shift;
127              
128             my ( %out, %in, %tmp, $tmp, $dtmp, @head );
129 22     22   1057  
130             @_ == 2 && (ref($_[1]) eq 'HASH')
131             or @_ % 2 == 1 && @_ == 5
132             or croak( "Wrong number of parameters in signature for %s: got %d, %s", "foo", scalar( @_ ), "that does not seem right" );
133              
134             @head = splice( @_, 0, 1 );
135              
136             # Parameter invocant (type: Defined)
137             (defined($head[0]))
138             or croak( "Type check failed in signature for foo: %s should be %s", "\$_[0]", "Defined" );
139              
140             %in = ( @_ == 1 and (ref($_[0]) eq 'HASH') ) ? %{ $_[0] } : @_;
141              
142             # Parameter xxx (type: Int)
143             exists( $in{"xxx"} )
144             or croak( "Failure in signature for foo: " . 'Missing required parameter: xxx' );
145             (do { my $tmp = $in{"xxx"}; defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/ })
146             or croak( "Type check failed in signature for foo: %s should be %s", "\$_{\"xxx\"}", "Int" );
147             $out{"xxx"} = $in{"xxx"} if exists( $in{"xxx"} );
148             delete( $in{"xxx"} );
149              
150             # Parameter yyy (type: Bool)
151             exists( $in{"yyy"} )
152             or croak( "Failure in signature for foo: " . 'Missing required parameter: yyy' );
153             (!ref $tmp and (!defined $tmp or $tmp eq q() or $tmp eq '0' or $tmp eq '1'))
154             or croak( "Type check failed in signature for foo: %s should be %s", "\$_{\"yyy\"}", "Bool" );
155             $out{"yyy"} = $tmp;
156             delete( $in{"yyy"} );
157              
158             # Unrecognized parameters
159             croak( "Failure in signature for foo: " . sprintf( q{Unrecognized parameter%s: %s}, keys( %in ) > 1 ? q{s} : q{}, join( q{, }, sort keys %in ) ) ) if keys %in;
160              
161             do { @_ = ( @head, $out{"xxx"}, $out{"yyy"} ); goto $__NEXT__ };
162             };
163              
164              
165             1;