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             package Mite::App::Command;
4 16     16   166 use strict;
  16         46  
  16         566  
5 16     16   13937 use warnings;
  16         64  
  16         739  
6 16     16   112 no warnings qw( once void );
  16         55  
  16         2309  
7              
8             our $USES_MITE = "Mite::Class";
9             our $MITE_SHIM = "Mite::Shim";
10             our $MITE_VERSION = "0.011000";
11              
12             # Mite keywords
13             BEGIN {
14 16     16   93 my ( $SHIM, $CALLER ) =
15             ( "Mite::Shim", "Mite::App::Command" );
16             (
17             *after, *around, *before, *extends, *field,
18             *has, *param, *signature_for, *with
19             )
20 16         56 = do {
21              
22             package Mite::Shim;
23 16     16   119 no warnings 'redefine';
  16         45  
  16         3799  
24             (
25 0     0   0 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
26 0     0   0 sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
27 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
28       0     sub { },
29 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
30 32     32   351 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
31 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
32 0     0   0 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
33 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
34 16         3174 );
35             };
36             }
37              
38             # Mite imports
39             BEGIN {
40 16     16   139 require Scalar::Util;
41 16         103 *STRICT = \&Mite::Shim::STRICT;
42 16         55 *bare = \&Mite::Shim::bare;
43 16         51 *blessed = \&Scalar::Util::blessed;
44 16         46 *carp = \&Mite::Shim::carp;
45 16         56 *confess = \&Mite::Shim::confess;
46 16         45 *croak = \&Mite::Shim::croak;
47 16         32 *false = \&Mite::Shim::false;
48 16         51 *guard = \&Mite::Shim::guard;
49 16         53 *lazy = \&Mite::Shim::lazy;
50 16         62 *lock = \&Mite::Shim::lock;
51 16         43 *ro = \&Mite::Shim::ro;
52 16         33 *rw = \&Mite::Shim::rw;
53 16         54 *rwp = \&Mite::Shim::rwp;
54 16         68 *true = \&Mite::Shim::true;
55 16         574 *unlock = \&Mite::Shim::unlock;
56             }
57              
58             # Gather metadata for constructor and destructor
59             sub __META__ {
60 16     16   124 no strict 'refs';
  16         42  
  16         13364  
61 80     80   214 my $class = shift;
62 80   33     329 $class = ref($class) || $class;
63 80         315 my $linear_isa = mro::get_linear_isa($class);
64             return {
65             BUILD => [
66 160 100       264 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  160         812  
  80         242  
67 160         471 map { "$_\::BUILD" } reverse @$linear_isa
68             ],
69             DEMOLISH => [
70 160 50       234 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  160         1773  
  0         0  
71 80         203 map { "$_\::DEMOLISH" } @$linear_isa
  160         419  
72             ],
73             HAS_BUILDARGS => $class->can('BUILDARGS'),
74             HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
75             };
76             }
77              
78             # Standard Moose/Moo-style constructor
79             sub new {
80 80 50   80 0 274 my $class = ref( $_[0] ) ? ref(shift) : shift;
81 80   33     593 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
82 80         241 my $self = bless {}, $class;
83             my $args =
84             $meta->{HAS_BUILDARGS}
85             ? $class->BUILDARGS(@_)
86 80 50       392 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
  0 50       0  
87 80         160 my $no_build = delete $args->{__no_BUILD__};
88              
89             # Attribute app (type: Object)
90             # has declaration, file lib/Mite/App/Command.pm, line 11
91 80 50       212 croak "Missing key in constructor: app" unless exists $args->{"app"};
92 80 50       381 blessed( $args->{"app"} )
93             or croak "Type check failed in constructor: %s should be %s", "app",
94             "Object";
95 80         438 $self->{"app"} = $args->{"app"};
96             require Scalar::Util && Scalar::Util::weaken( $self->{"app"} )
97 80 50 50     883 if ref $self->{"app"};
98              
99             # Attribute kingpin_command (type: Object)
100             # has declaration, file lib/Mite/App/Command.pm, line 19
101 80 50       195 if ( exists $args->{"kingpin_command"} ) {
102 0 0       0 blessed( $args->{"kingpin_command"} )
103             or croak "Type check failed in constructor: %s should be %s",
104             "kingpin_command", "Object";
105 0         0 $self->{"kingpin_command"} = $args->{"kingpin_command"};
106             }
107              
108             # Call BUILD methods
109 80 50 33     274 $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
  80 50       722  
110              
111             # Unrecognized parameters
112 80         155 my @unknown = grep not(/\A(?:app|kingpin_command)\z/), keys %{$args};
  80         586  
113             @unknown
114 80 50       253 and croak(
115             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
116              
117 80         531 return $self;
118             }
119              
120             # Used by constructor to call BUILD methods
121             sub BUILDALL {
122 80     80 0 189 my $class = ref( $_[0] );
123 80   33     233 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
124 80 50       130 $_->(@_) for @{ $meta->{BUILD} || [] };
  80         385  
125             }
126              
127             # Destructor should call DEMOLISH methods
128             sub DESTROY {
129 80     80   159 my $self = shift;
130 80   33     200 my $class = ref($self) || $self;
131 80   33     240 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
132 80 50       236 my $in_global_destruction =
133             defined ${^GLOBAL_PHASE}
134             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
135             : Devel::GlobalDestruction::in_global_destruction();
136 80 50       144 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  80         299  
137 0         0 my $e = do {
138 0         0 local ( $?, $@ );
139 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
140 0         0 $@;
141             };
142 16     16   146 no warnings 'misc'; # avoid (in cleanup) warnings
  16         45  
  16         9912  
143 0 0       0 die $e if $e; # rethrow
144             }
145 80         1157 return;
146             }
147              
148             my $__XS = !$ENV{PERL_ONLY}
149             && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
150              
151             # Accessors for app
152             # has declaration, file lib/Mite/App/Command.pm, line 11
153             if ($__XS) {
154             Class::XSAccessor->import(
155             chained => 1,
156             "getters" => { "app" => "app" },
157             );
158             }
159             else {
160             *app = sub {
161             @_ == 1 or croak('Reader "app" usage: $self->app()');
162             $_[0]{"app"};
163             };
164             }
165              
166             sub _assert_blessed_app {
167 109     109   177 my $object = do { $_[0]{"app"} };
  109         267  
168 109 50       490 blessed($object) or croak("app is not a blessed object");
169 109         566 $object;
170             }
171              
172             # Delegated methods for app
173             # has declaration, file lib/Mite/App/Command.pm, line 11
174 17     17 0 82 sub config { shift->_assert_blessed_app->config(@_) }
175 80     80 0 352 sub kingpin { shift->_assert_blessed_app->kingpin(@_) }
176 12     12 0 81 sub project { shift->_assert_blessed_app->project(@_) }
177              
178             # Accessors for kingpin_command
179             # has declaration, file lib/Mite/App/Command.pm, line 19
180             sub kingpin_command {
181 88 50   88 0 266 @_ == 1
182             or croak('Reader "kingpin_command" usage: $self->kingpin_command()');
183             (
184             exists( $_[0]{"kingpin_command"} ) ? $_[0]{"kingpin_command"} : (
185 88 100       410 $_[0]{"kingpin_command"} = do {
186 80         1345 my $default_value = $_[0]->_build_kingpin_command;
187 80 50       5893 blessed($default_value)
188             or croak( "Type check failed in default: %s should be %s",
189             "kingpin_command", "Object" );
190 80         1140 $default_value;
191             }
192             )
193             );
194             }
195              
196             # See UNIVERSAL
197             sub DOES {
198 0     0 0   my ( $self, $role ) = @_;
199 0           our %DOES;
200 0 0         return $DOES{$role} if exists $DOES{$role};
201 0 0         return 1 if $role eq __PACKAGE__;
202 0 0 0       if ( $INC{'Moose/Util.pm'}
      0        
203             and my $meta = Moose::Util::find_meta( ref $self or $self ) )
204             {
205 0 0 0       $meta->can('does_role') and $meta->does_role($role) and return 1;
206             }
207 0           return $self->SUPER::DOES($role);
208             }
209              
210             # Alias for Moose/Moo-compatibility
211             sub does {
212 0     0 0   shift->DOES(@_);
213             }
214              
215             1;
216             }