File Coverage

/tmp/oaZ0QvnnN9.mite.pm
Criterion Covered Total %
statement 57 84 67.8
branch 15 38 39.4
condition 6 27 22.2
subroutine 14 24 58.3
pod n/a
total 92 173 53.1


line stmt bran cond sub pod time code
1             {
2             package MyTest;
3 1     1   7 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         2  
  1         28  
5 1     1   4 no warnings qw( once void );
  1         3  
  1         171  
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   7 my ( $SHIM, $CALLER ) = ( "Mite::Shim", "MyTest" );
13 1         1 ( *after, *around, *before, *extends, *field, *has, *param, *signature_for, *with ) = do {
14             package Mite::Shim;
15 1     1   7 no warnings 'redefine';
  1         2  
  1         256  
16             (
17 0     0   0 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
18 0     0   0 sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
19 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
20       0     sub {},
21 1     1   14 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
22 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
23 1     1   10 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
24 0     0   0 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
25 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
26 1         61 );
27             };
28             };
29              
30             # Mite imports
31             BEGIN {
32 1     1   4 *false = \&Mite::Shim::false;
33 1         38 *true = \&Mite::Shim::true;
34             };
35              
36             # Gather metadata for constructor and destructor
37             sub __META__ {
38 1     1   6 no strict 'refs';
  1         2  
  1         704  
39 1   33 1   2 my $class = shift; $class = ref($class) || $class;
  1         6  
40 1         8 my $linear_isa = mro::get_linear_isa( $class );
41             return {
42             BUILD => [
43 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         6  
  0         0  
44 1         3 map { "$_\::BUILD" } reverse @$linear_isa
45             ],
46             DEMOLISH => [
47 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         16  
  0         0  
48 1         2 map { "$_\::DEMOLISH" } @$linear_isa
  1         3  
49             ],
50             HAS_BUILDARGS => $class->can('BUILDARGS'),
51             HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
52             };
53             }
54              
55              
56             # Standard Moose/Moo-style constructor
57             sub new {
58 3 50   3   3339 my $class = ref($_[0]) ? ref(shift) : shift;
59 3   66     12 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
60 3         13 my $self = bless {}, $class;
61 3 50       12 my $args = $meta->{HAS_BUILDARGS} ? $class->BUILDARGS( @_ ) : { ( @_ == 1 ) ? %{$_[0]} : @_ };
  0 50       0  
62 3         5 my $no_build = delete $args->{__no_BUILD__};
63              
64             # Attribute foo
65             # param declaration, file ../../../../tmp/oaZ0QvnnN9, line 3
66 3 100       15 Mite::Shim::croak "Missing key in constructor: foo" unless exists $args->{"foo"};
67 2         6 $self->{"foo"} = $args->{"foo"};
68              
69              
70             # Call BUILD methods
71 2 50 33     6 $self->BUILDALL( $args ) if ( ! $no_build and @{ $meta->{BUILD} || [] } );
  2 50       8  
72              
73             # Unrecognized parameters
74 2 100       3 my @unknown = grep not( /\Afoo\z/ ), keys %{$args}; @unknown and Mite::Shim::croak( "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
  2         14  
  2         12  
75              
76 1         7 return $self;
77             }
78              
79             # Used by constructor to call BUILD methods
80             sub BUILDALL {
81 0     0   0 my $class = ref( $_[0] );
82 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
83 0 0       0 $_->( @_ ) for @{ $meta->{BUILD} || [] };
  0         0  
84             }
85              
86             # Destructor should call DEMOLISH methods
87             sub DESTROY {
88 3     3   598 my $self = shift;
89 3   33     9 my $class = ref( $self ) || $self;
90 3   33     10 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
91 3 50       11 my $in_global_destruction = defined ${^GLOBAL_PHASE}
92             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
93             : Devel::GlobalDestruction::in_global_destruction();
94 3 50       5 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  3         12  
95 0         0 my $e = do {
96 0         0 local ( $?, $@ );
97 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
98 0         0 $@;
99             };
100 1     1   8 no warnings 'misc'; # avoid (in cleanup) warnings
  1         2  
  1         588  
101 0 0       0 die $e if $e; # rethrow
102             }
103 3         21 return;
104             }
105              
106             my $__XS = !$ENV{PERL_ONLY} && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
107              
108             # Accessors for bar
109             # field declaration, file ../../../../tmp/oaZ0QvnnN9, line 4
110 1 50   1   1255 sub bar { @_ == 1 or Mite::Shim::croak( 'Reader "bar" usage: $self->bar()' ); ( exists($_[0]{"bar"}) ? $_[0]{"bar"} : ( $_[0]{"bar"} = $_[0]->_build_bar ) ) }
  1 50       5  
111              
112             # Accessors for foo
113             # param declaration, file ../../../../tmp/oaZ0QvnnN9, line 3
114             if ( $__XS ) {
115             Class::XSAccessor->import(
116             chained => 1,
117             "getters" => { "foo" => "foo" },
118             );
119             }
120             else {
121             *foo = sub { @_ == 1 or Mite::Shim::croak( 'Reader "foo" usage: $self->foo()' ); $_[0]{"foo"} };
122             }
123              
124              
125             # See UNIVERSAL
126             sub DOES {
127 0     0     my ( $self, $role ) = @_;
128 0           our %DOES;
129 0 0         return $DOES{$role} if exists $DOES{$role};
130 0 0         return 1 if $role eq __PACKAGE__;
131 0 0 0       if ( $INC{'Moose/Util.pm'} and my $meta = Moose::Util::find_meta( ref $self or $self ) ) {
      0        
132 0 0 0       $meta->can( 'does_role' ) and $meta->does_role( $role ) and return 1;
133             }
134 0           return $self->SUPER::DOES( $role );
135             }
136              
137             # Alias for Moose/Moo-compatibility
138             sub does {
139 0     0     shift->DOES( @_ );
140             }
141              
142             1;
143             }