File Coverage

blib/lib/Mite/App/Command.pm.mite.pm
Criterion Covered Total %
statement 88 113 77.8
branch 21 50 42.0
condition 7 29 24.1
subroutine 18 28 64.2
pod 0 8 0.0
total 134 228 58.7


line stmt bran cond sub pod time code
1             {
2              
3             use strict;
4 16     16   136 use warnings;
  16         60  
  16         578  
5 16     16   12077 no warnings qw( once void );
  16         48  
  16         11975  
6 16     16   126  
  16         37  
  16         2184  
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Mite::Shim";
9             our $MITE_VERSION = "0.011000";
10              
11             # Mite keywords
12             BEGIN {
13             my ( $SHIM, $CALLER ) =
14 16     16   101 ( "Mite::Shim", "Mite::App::Command" );
15             (
16             *after, *around, *before, *extends, *field,
17             *has, *param, *signature_for, *with
18             )
19             = do {
20 16         44  
21             no warnings 'redefine';
22             (
23 16     16   12461 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
  16         74  
  16         3806  
24             sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
25 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
26 0     0   0 sub { },
27 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
28       0     sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
29 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
30 32     32   302 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
31 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
32 0     0   0 );
33 0     0   0 }
34 16         3094  
35             # Mite imports
36             BEGIN {
37             require Scalar::Util;
38             *STRICT = \&Mite::Shim::STRICT;
39             *bare = \&Mite::Shim::bare;
40 16     16   166 *blessed = \&Scalar::Util::blessed;
41 16         66 *carp = \&Mite::Shim::carp;
42 16         47 *confess = \&Mite::Shim::confess;
43 16         41 *croak = \&Mite::Shim::croak;
44 16         58 *false = \&Mite::Shim::false;
45 16         47 *guard = \&Mite::Shim::guard;
46 16         55 *lazy = \&Mite::Shim::lazy;
47 16         56 *lock = \&Mite::Shim::lock;
48 16         56 *ro = \&Mite::Shim::ro;
49 16         44 *rw = \&Mite::Shim::rw;
50 16         48 *rwp = \&Mite::Shim::rwp;
51 16         52 *true = \&Mite::Shim::true;
52 16         38 *unlock = \&Mite::Shim::unlock;
53 16         55 }
54 16         54  
55 16         619 # Gather metadata for constructor and destructor
56             no strict 'refs';
57             my $class = shift;
58             $class = ref($class) || $class;
59             my $linear_isa = mro::get_linear_isa($class);
60 16     16   105 return {
  16         43  
  16         13019  
61 80     80   184 BUILD => [
62 80   33     346 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
63 80         311 map { "$_\::BUILD" } reverse @$linear_isa
64             ],
65             DEMOLISH => [
66 160 100       258 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  160         908  
  80         245  
67 160         519 map { "$_\::DEMOLISH" } @$linear_isa
68             ],
69             HAS_BUILDARGS => $class->can('BUILDARGS'),
70 160 50       246 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
  160         1730  
  0         0  
71 80         265 };
  160         430  
72             }
73              
74             # Standard Moose/Moo-style constructor
75             my $class = ref( $_[0] ) ? ref(shift) : shift;
76             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
77             my $self = bless {}, $class;
78             my $args =
79             $meta->{HAS_BUILDARGS}
80 80 50   80 0 287 ? $class->BUILDARGS(@_)
81 80   33     631 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
82 80         249 my $no_build = delete $args->{__no_BUILD__};
83              
84             # Attribute app (type: Object)
85             # has declaration, file lib/Mite/App/Command.pm, line 11
86 80 50       410 croak "Missing key in constructor: app" unless exists $args->{"app"};
  0 50       0  
87 80         178 blessed( $args->{"app"} )
88             or croak "Type check failed in constructor: %s should be %s", "app",
89             "Object";
90             $self->{"app"} = $args->{"app"};
91 80 50       224 require Scalar::Util && Scalar::Util::weaken( $self->{"app"} )
92 80 50       361 if ref $self->{"app"};
93              
94             # Attribute kingpin_command (type: Object)
95 80         461 # has declaration, file lib/Mite/App/Command.pm, line 19
96             if ( exists $args->{"kingpin_command"} ) {
97 80 50 50     879 blessed( $args->{"kingpin_command"} )
98             or croak "Type check failed in constructor: %s should be %s",
99             "kingpin_command", "Object";
100             $self->{"kingpin_command"} = $args->{"kingpin_command"};
101 80 50       205 }
102 0 0       0  
103             # Call BUILD methods
104             $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
105 0         0  
106             # Unrecognized parameters
107             my @unknown = grep not(/\A(?:app|kingpin_command)\z/), keys %{$args};
108             @unknown
109 80 50 33     228 and croak(
  80 50       755  
110             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
111              
112 80         148 return $self;
  80         587  
113             }
114 80 50       254  
115             # Used by constructor to call BUILD methods
116             my $class = ref( $_[0] );
117 80         431 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
118             $_->(@_) for @{ $meta->{BUILD} || [] };
119             }
120              
121             # Destructor should call DEMOLISH methods
122 80     80 0 176 my $self = shift;
123 80   33     226 my $class = ref($self) || $self;
124 80 50       133 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
  80         383  
125             my $in_global_destruction =
126             defined ${^GLOBAL_PHASE}
127             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
128             : Devel::GlobalDestruction::in_global_destruction();
129 80     80   185 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
130 80   33     206 my $e = do {
131 80   33     224 local ( $?, $@ );
132 80 50       226 eval { $demolisher->( $self, $in_global_destruction ) };
133             $@;
134             };
135             no warnings 'misc'; # avoid (in cleanup) warnings
136 80 50       139 die $e if $e; # rethrow
  80         286  
137 0         0 }
138 0         0 return;
139 0         0 }
  0         0  
140 0         0  
141             my $__XS = !$ENV{PERL_ONLY}
142 16     16   142 && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
  16         49  
  16         9739  
143 0 0       0  
144             # Accessors for app
145 80         1023 # has declaration, file lib/Mite/App/Command.pm, line 11
146             if ($__XS) {
147             Class::XSAccessor->import(
148             chained => 1,
149             "getters" => { "app" => "app" },
150             );
151             }
152             else {
153             *app = sub {
154             @_ == 1 or croak('Reader "app" usage: $self->app()');
155             $_[0]{"app"};
156             };
157             }
158              
159             my $object = do { $_[0]{"app"} };
160             blessed($object) or croak("app is not a blessed object");
161             $object;
162             }
163              
164             # Delegated methods for app
165             # has declaration, file lib/Mite/App/Command.pm, line 11
166              
167 109     109   206 # Accessors for kingpin_command
  109         280  
168 109 50       507 # has declaration, file lib/Mite/App/Command.pm, line 19
169 109         569 @_ == 1
170             or croak('Reader "kingpin_command" usage: $self->kingpin_command()');
171             (
172             exists( $_[0]{"kingpin_command"} ) ? $_[0]{"kingpin_command"} : (
173             $_[0]{"kingpin_command"} = do {
174 17     17 0 89 my $default_value = $_[0]->_build_kingpin_command;
175 80     80 0 388 blessed($default_value)
176 12     12 0 75 or croak( "Type check failed in default: %s should be %s",
177             "kingpin_command", "Object" );
178             $default_value;
179             }
180             )
181 88 50   88 0 269 );
182             }
183              
184             # See UNIVERSAL
185 88 100       431 my ( $self, $role ) = @_;
186 80         1314 our %DOES;
187 80 50       5858 return $DOES{$role} if exists $DOES{$role};
188             return 1 if $role eq __PACKAGE__;
189             if ( $INC{'Moose/Util.pm'}
190 80         1086 and my $meta = Moose::Util::find_meta( ref $self or $self ) )
191             {
192             $meta->can('does_role') and $meta->does_role($role) and return 1;
193             }
194             return $self->SUPER::DOES($role);
195             }
196              
197             # Alias for Moose/Moo-compatibility
198 0     0 0   shift->DOES(@_);
199 0           }
200 0 0          
201 0 0         1;