File Coverage

blib/lib/Sub/HandlesVia/Toolkit.pm.mite.pm
Criterion Covered Total %
statement 28 78 35.9
branch 3 36 8.3
condition 3 27 11.1
subroutine 9 13 69.2
pod 0 4 0.0
total 43 158 27.2


line stmt bran cond sub pod time code
1             {
2              
3             use strict;
4 92     92   734 use warnings;
  92         232  
  92         2729  
5 92     92   505 no warnings qw( once void );
  92         216  
  92         2620  
6 92     92   504  
  92         230  
  92         11408  
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Sub::HandlesVia::Mite";
9             our $MITE_VERSION = "0.010008";
10              
11             # Mite keywords
12             BEGIN {
13             my ( $SHIM, $CALLER ) =
14 92     92   475 ( "Sub::HandlesVia::Mite", "Sub::HandlesVia::Toolkit" );
15             ( *after, *around, *before, *extends, *has, *signature_for, *with ) =
16             do {
17 92         238  
18             no warnings 'redefine';
19             (
20 92     92   732 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
  92         238  
  92         17917  
21             sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
22 0         0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
23 0         0 sub { },
24 0         0 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
25             sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
26 0         0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
27 0         0 );
28 0         0 }
29 92         4661  
30             # Gather metadata for constructor and destructor
31             no strict 'refs';
32             my $class = shift;
33             $class = ref($class) || $class;
34             my $linear_isa = mro::get_linear_isa($class);
35 92     92   629 return {
  92         1194  
  92         58104  
36 0     0   0 BUILD => [
37 0   0     0 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
38 0         0 map { "$_\::BUILD" } reverse @$linear_isa
39             ],
40             DEMOLISH => [
41 0 0       0 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  0         0  
  0         0  
42 0         0 map { "$_\::DEMOLISH" } @$linear_isa
43             ],
44             HAS_BUILDARGS => $class->can('BUILDARGS'),
45 0 0       0 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
  0         0  
  0         0  
46 0         0 };
  0         0  
47             }
48              
49             # Standard Moose/Moo-style constructor
50             my $class = ref( $_[0] ) ? ref(shift) : shift;
51             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
52             my $self = bless {}, $class;
53             my $args =
54             $meta->{HAS_BUILDARGS}
55 0 0   0 0 0 ? $class->BUILDARGS(@_)
56 0   0     0 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
57 0         0 my $no_build = delete $args->{__no_BUILD__};
58              
59             # Call BUILD methods
60             $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
61 0 0       0  
  0 0       0  
62 0         0 # Unrecognized parameters
63             my @unknown = grep not(
64             do {
65 0 0 0     0  
  0 0       0  
66             defined($_) and do {
67             ref( \$_ ) eq 'SCALAR'
68             or ref( \( my $val = $_ ) ) eq 'SCALAR';
69             }
70             ),
71             keys %{$args};
72 0 0       0 @unknown
73 0 0       0 and Sub::HandlesVia::Mite::croak(
74             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
75              
76             return $self;
77             }
78 0         0  
  0         0  
79             # Used by constructor to call BUILD methods
80 0 0       0 my $class = ref( $_[0] );
81             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
82             $_->(@_) for @{ $meta->{BUILD} || [] };
83 0         0 }
84              
85             # Destructor should call DEMOLISH methods
86             my $self = shift;
87             my $class = ref($self) || $self;
88 0     0 0 0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
89 0   0     0 my $in_global_destruction =
90 0 0       0 defined ${^GLOBAL_PHASE}
  0         0  
91             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
92             : Devel::GlobalDestruction::in_global_destruction();
93             for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
94             my $e = do {
95 0     0   0 local ( $?, $@ );
96 0   0     0 eval { $demolisher->( $self, $in_global_destruction ) };
97 0   0     0 $@;
98 0 0       0 };
99             no warnings 'misc'; # avoid (in cleanup) warnings
100             die $e if $e; # rethrow
101             }
102 0 0       0 return;
  0         0  
103 0         0 }
104 0         0  
105 0         0 # See UNIVERSAL
  0         0  
106 0         0 my ( $self, $role ) = @_;
107             our %DOES;
108 92     92   795 return $DOES{$role} if exists $DOES{$role};
  92         226  
  92         22996  
109 0 0       0 return 1 if $role eq __PACKAGE__;
110             if ( $INC{'Moose/Util.pm'}
111 0         0 and my $meta = Moose::Util::find_meta( ref $self or $self ) )
112             {
113             $meta->can('does_role') and $meta->does_role($role) and return 1;
114             }
115             return $self->SUPER::DOES($role);
116 3901     3901 0 7079 }
117 3901         5564  
118 3901 50       7527 # Alias for Moose/Moo-compatibility
119 3901 50       7538 shift->DOES(@_);
120 3901 50 33     9548 }
      66        
121              
122             1;