File Coverage

/tmp/oNL4RD3UeT.mite.pm
Criterion Covered Total %
statement 92 114 80.7
branch 26 60 43.3
condition 8 36 22.2
subroutine 14 15 93.3
pod n/a
total 140 225 62.2


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   4 use warnings;
  1         3  
  1         26  
5 1     1   5 no warnings qw( once void );
  1         4  
  1         206  
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", "MyTest" );
13 1         1 ( *after, *around, *before, *extends, *has, *signature_for, *with ) = do {
14             package Mite::Shim;
15 1     1   9 no warnings 'redefine';
  1         2  
  1         199  
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 1         6 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         58 );
25             };
26             };
27              
28             # Gather metadata for constructor and destructor
29             sub __META__ {
30 1     1   6 no strict 'refs';
  1         1  
  1         821  
31 1   33 1   2 my $class = shift; $class = ref($class) || $class;
  1         5  
32 1         6 my $linear_isa = mro::get_linear_isa( $class );
33             return {
34             BUILD => [
35 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         7  
  0         0  
36 1         4 map { "$_\::BUILD" } reverse @$linear_isa
37             ],
38             DEMOLISH => [
39 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         16  
  0         0  
40 1         3 map { "$_\::DEMOLISH" } @$linear_isa
  1         3  
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   142 my $class = ref($_[0]) ? ref(shift) : shift;
51 1   33     6 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
52 1         3 my $self = bless {}, $class;
53 1 50       6 my $args = $meta->{HAS_BUILDARGS} ? $class->BUILDARGS( @_ ) : { ( @_ == 1 ) ? %{$_[0]} : @_ };
  0 50       0  
54 1         2 my $no_build = delete $args->{__no_BUILD__};
55              
56             # Attribute foo (type: ArrayRef[Int])
57             # has declaration, file ../../../../tmp/oNL4RD3UeT, line 3
58 1 50 0     2 do { my $value = exists( $args->{"foo"} ) ? $args->{"foo"} : []; do { package MyTest::__SAFE_NAMESPACE__; (ref($value) eq 'ARRAY') and do { my $ok = 1; for my $i (@{$value}) { ($ok = 0, last) unless (do { my $tmp = $i; defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/ }) }; $ok } } or Mite::Shim::croak "Type check failed in constructor: %s should be %s", "foo", "ArrayRef[Int]"; $self->{"foo"} = $value; };
  1 0       3  
  1 0       1  
  1 50       7  
  1 50       1  
  1         2  
  1         2  
  0         0  
  0         0  
  0         0  
  1         5  
  1         4  
59 1 50       6 Mite::Shim::lock($self->{"foo"}) if ref $self->{"foo"};
60              
61              
62             # Call BUILD methods
63 1 50 33     4 $self->BUILDALL( $args ) if ( ! $no_build and @{ $meta->{BUILD} || [] } );
  1 50       5  
64              
65             # Unrecognized parameters
66 1 50       2 my @unknown = grep not( /\Afoo\z/ ), keys %{$args}; @unknown and Mite::Shim::croak( "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
  1         3  
  1         3  
67              
68 1         4 return $self;
69             }
70              
71             # Used by constructor to call BUILD methods
72             sub BUILDALL {
73 0     0   0 my $class = ref( $_[0] );
74 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
75 0 0       0 $_->( @_ ) for @{ $meta->{BUILD} || [] };
  0         0  
76             }
77              
78             # Destructor should call DEMOLISH methods
79             sub DESTROY {
80 1     1   1952 my $self = shift;
81 1   33     4 my $class = ref( $self ) || $self;
82 1   33     4 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
83 1 50       17 my $in_global_destruction = defined ${^GLOBAL_PHASE}
84             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
85             : Devel::GlobalDestruction::in_global_destruction();
86 1 50       3 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  1         5  
87 0         0 my $e = do {
88 0         0 local ( $?, $@ );
89 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
90 0         0 $@;
91             };
92 1     1   8 no warnings 'misc'; # avoid (in cleanup) warnings
  1         1  
  1         635  
93 0 0       0 die $e if $e; # rethrow
94             }
95 1         8 return;
96             }
97              
98             my $__XS = !$ENV{PERL_ONLY} && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
99              
100             # Accessors for foo
101             # has declaration, file ../../../../tmp/oNL4RD3UeT, line 3
102 9 50 33 9   930 sub foo { @_ > 1 ? do { do { package MyTest::__SAFE_NAMESPACE__; (ref($_[1]) eq 'ARRAY') and do { my $ok = 1; for my $i (@{$_[1]}) { ($ok = 0, last) unless (do { my $tmp = $i; defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/ }) }; $ok } } or Mite::Shim::croak( "Type check failed in %s: value should be %s", "accessor", "ArrayRef[Int]" ); $_[0]{"foo"} = $_[1]; Mite::Shim::lock($_[0]{"foo"}) if ref $_[0]{"foo"}; $_[0]; } : ( $_[0]{"foo"} ) }
  1 50       4  
  1 50       30  
  1 50       4  
  1 50       3  
  1 100       3  
  9         10  
  9         9  
  9         52  
  1         5  
  1         3  
  1         10  
  1         2  
103              
104             # Delegated methods for foo
105             # has declaration, file ../../../../tmp/oNL4RD3UeT, line 3
106             *add_foo = sub {
107 2     2   7 my $mite_guard = Mite::Shim::unlock($_[0]->{"foo"});
108 2         4 my $shv_self=shift;
109 2 50 33     4 for my $shv_value (@_) { do { (do { my $tmp = $shv_value; defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/ }) or Mite::Shim::croak("Type check failed in delegated method: expected %s, got value %s", "Int", $shv_value); $shv_value }; }
  4 50       5  
  4         5  
  4         4  
  4         33  
  4         9  
110 2         2 my $shv_ref_invocant = do { $shv_self->foo };
  2         5  
111 2         3 push(@{$shv_ref_invocant}, @_)
  2         18  
112             };
113              
114             # See UNIVERSAL
115             sub DOES {
116 7     7   13 my ( $self, $role ) = @_;
117 7         7 our %DOES;
118 7 50       14 return $DOES{$role} if exists $DOES{$role};
119 7 50       12 return 1 if $role eq __PACKAGE__;
120 7 50 0     14 if ( $INC{'Moose/Util.pm'} and my $meta = Moose::Util::find_meta( ref $self or $self ) ) {
      33        
121 0 0 0     0 $meta->can( 'does_role' ) and $meta->does_role( $role ) and return 1;
122             }
123 7         39 return $self->SUPER::DOES( $role );
124             }
125              
126             # Alias for Moose/Moo-compatibility
127             sub does {
128 7     7   2135 shift->DOES( @_ );
129             }
130              
131             1;
132             }