File Coverage

/tmp/Ao5RWkZRrK.mite.pm
Criterion Covered Total %
statement 61 80 76.2
branch 17 36 47.2
condition 7 27 25.9
subroutine 12 13 92.3
pod n/a
total 97 156 62.1


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