File Coverage

blib/lib/Mite/App/Command.pm.mite.pm
Criterion Covered Total %
statement 86 109 78.9
branch 21 46 45.6
condition 7 20 35.0
subroutine 18 28 64.2
pod 0 8 0.0
total 132 211 62.5


line stmt bran cond sub pod time code
1             {
2              
3             use strict;
4 16     16   105 use warnings;
  16         37  
  16         461  
5 16     16   74 no warnings qw( once void );
  16         66  
  16         587  
6 16     16   86  
  16         46  
  16         2075  
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Mite::Shim";
9             our $MITE_VERSION = "0.010007";
10              
11             # Mite keywords
12             BEGIN {
13             my ( $SHIM, $CALLER ) =
14 16     16   85 ( "Mite::Shim", "Mite::App::Command" );
15             (
16             *after, *around, *before, *extends, *field,
17             *has, *param, *signature_for, *with
18             )
19             = do {
20 16         33  
21             no warnings 'redefine';
22             (
23 16     16   117 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
  16         49  
  16         3493  
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   235 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         3457  
35             # Mite imports
36             BEGIN {
37             require Scalar::Util;
38             *STRICT = \&Mite::Shim::STRICT;
39             *bare = \&Mite::Shim::bare;
40 16     16   124 *blessed = \&Scalar::Util::blessed;
41 16         57 *carp = \&Mite::Shim::carp;
42 16         40 *confess = \&Mite::Shim::confess;
43 16         58 *croak = \&Mite::Shim::croak;
44 16         53 *false = \&Mite::Shim::false;
45 16         40 *guard = \&Mite::Shim::guard;
46 16         33 *lazy = \&Mite::Shim::lazy;
47 16         46 *ro = \&Mite::Shim::ro;
48 16         49 *rw = \&Mite::Shim::rw;
49 16         37 *rwp = \&Mite::Shim::rwp;
50 16         39 *true = \&Mite::Shim::true;
51 16         38 }
52 16         34  
53 16         515 # Gather metadata for constructor and destructor
54             no strict 'refs';
55             my $class = shift;
56             $class = ref($class) || $class;
57             my $linear_isa = mro::get_linear_isa($class);
58 16     16   104 return {
  16         31  
  16         11079  
59 80     80   147 BUILD => [
60 80   33     309 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
61 80         272 map { "$_\::BUILD" } reverse @$linear_isa
62             ],
63             DEMOLISH => [
64 160 100       201 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  160         717  
  80         198  
65 160         439 map { "$_\::DEMOLISH" } @$linear_isa
66             ],
67             HAS_BUILDARGS => $class->can('BUILDARGS'),
68 160 50       204 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
  160         1506  
  0         0  
69 80         207 };
  160         332  
70             }
71              
72             # Standard Moose/Moo-style constructor
73             my $class = ref( $_[0] ) ? ref(shift) : shift;
74             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
75             my $self = bless {}, $class;
76             my $args =
77             $meta->{HAS_BUILDARGS}
78 80 50   80 0 243 ? $class->BUILDARGS(@_)
79 80   33     512 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
80 80         257 my $no_build = delete $args->{__no_BUILD__};
81              
82             # Attribute app (type: Object)
83             # has declaration, file lib/Mite/App/Command.pm, line 11
84 80 50       362 croak "Missing key in constructor: app" unless exists $args->{"app"};
  0 50       0  
85 80         148 blessed( $args->{"app"} )
86             or croak "Type check failed in constructor: %s should be %s", "app",
87             "Object";
88             $self->{"app"} = $args->{"app"};
89 80 50       180 require Scalar::Util && Scalar::Util::weaken( $self->{"app"} )
90 80 50       311 if ref $self->{"app"};
91              
92             # Attribute kingpin_command (type: Object)
93 80         378 # has declaration, file lib/Mite/App/Command.pm, line 19
94             if ( exists $args->{"kingpin_command"} ) {
95 80 50 50     740 blessed( $args->{"kingpin_command"} )
96             or croak "Type check failed in constructor: %s should be %s",
97             "kingpin_command", "Object";
98             $self->{"kingpin_command"} = $args->{"kingpin_command"};
99 80 50       191 }
100 0 0       0  
101             # Call BUILD methods
102             $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
103 0         0  
104             # Unrecognized parameters
105             my @unknown = grep not(/\A(?:app|kingpin_command)\z/), keys %{$args};
106             @unknown
107 80 50 33     204 and croak(
  80 50       625  
108             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
109              
110 80         131 return $self;
  80         541  
111             }
112 80 50       213  
113             # Used by constructor to call BUILD methods
114             my $class = ref( $_[0] );
115 80         372 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
116             $_->(@_) for @{ $meta->{BUILD} || [] };
117             }
118              
119             # Destructor should call DEMOLISH methods
120 80     80 0 165 my $self = shift;
121 80   33     186 my $class = ref($self) || $self;
122 80 50       116 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
  80         338  
123             my $in_global_destruction =
124             defined ${^GLOBAL_PHASE}
125             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
126             : Devel::GlobalDestruction::in_global_destruction();
127 80     80   114 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
128 80   33     172 my $e = do {
129 80   33     179 local ( $?, $@ );
130 80 50       198 eval { $demolisher->( $self, $in_global_destruction ) };
131             $@;
132             };
133             no warnings 'misc'; # avoid (in cleanup) warnings
134 80 50       109 die $e if $e; # rethrow
  80         258  
135 0         0 }
136 0         0 return;
137 0         0 }
  0         0  
138 0         0  
139             my $__XS = !$ENV{PERL_ONLY}
140 16     16   112 && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
  16         40  
  16         7717  
141 0 0       0  
142             # Accessors for app
143 80         983 # has declaration, file lib/Mite/App/Command.pm, line 11
144             if ($__XS) {
145             Class::XSAccessor->import(
146             chained => 1,
147             "getters" => { "app" => "app" },
148             );
149             }
150             else {
151             *app = sub {
152             @_ == 1 or croak('Reader "app" usage: $self->app()');
153             $_[0]{"app"};
154             };
155             }
156              
157             my $object = do { $_[0]{"app"} };
158             blessed($object) or croak("app is not a blessed object");
159             $object;
160             }
161              
162             # Delegated methods for app
163             # has declaration, file lib/Mite/App/Command.pm, line 11
164              
165 109     109   172 # Accessors for kingpin_command
  109         247  
166 109 50       466 # has declaration, file lib/Mite/App/Command.pm, line 19
167 109         570 @_ == 1
168             or croak('Reader "kingpin_command" usage: $self->kingpin_command()');
169             (
170             exists( $_[0]{"kingpin_command"} ) ? $_[0]{"kingpin_command"} : (
171             $_[0]{"kingpin_command"} = do {
172 17     17 0 71 my $default_value = $_[0]->_build_kingpin_command;
173 80     80 0 340 blessed($default_value)
174 12     12 0 53 or croak( "Type check failed in default: %s should be %s",
175             "kingpin_command", "Object" );
176             $default_value;
177             }
178             )
179 88 50   88 0 230 );
180             }
181              
182             # See UNIVERSAL
183 88 100       420 my ( $self, $role ) = @_;
184 80         1153 our %DOES;
185 80 50       4997 return $DOES{$role} if exists $DOES{$role};
186             return 1 if $role eq __PACKAGE__;
187             return $self->SUPER::DOES($role);
188 80         242 }
189              
190             # Alias for Moose/Moo-compatibility
191             shift->DOES(@_);
192             }
193              
194             1;
195