blib/lib/Pinto.pm

filter: Statementstmt 98.7% 78 / 79 Branchbran 100% 2 / 2 Conditioncond 55.5% 5 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 21 / 21 Podpod 0.0% 0 / 3 totaltotal 89.1% 107 / 120 CC 6 SCAR 3.8
CC
6
Cov
94%
run
3.0
load_class_for_action
2.1
__ANON__
2.0
CRAP 1.5
« blib/lib/App/Pinto/Command/unregister.pm ↑ Summary blib/lib/Pinto/Action/Nop.pm »
1 # ABSTRACT: Curate a repository of Perl modules
2  
3 package Pinto;
4  
5 54 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 54 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 54 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 54 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 54 ▶use Pinto::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 54 ▶use Pinto::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 54 ▶use Pinto::Chrome::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 54 ▶use Pinto::Types qw(Dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 54 ▶use Pinto::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #------------------------------------------------------------------------------
19  
20 # HACK: On perl-5.14.x (and possibly others) Package::Stash::XS has some funky
21 # behavior that causes Class::Load to think that certain modules are already
22 # loaded when they actually are not. I don't know why it happens. But loading
23 # those modules here explicitly prevents the problem. The module may or may not
24 # actually be used depending on your platform, and forcibly loading it anyway
25 # seems to be innocuous. We use Class::Load quite a lot in Pinto, so this same
26 # bug may manifest in other places too. For the moment, this these are the
27 # only ones that I'm aware of.
28  
29 54 ▶use Devel::StackTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 54 ▶use DateTime::TimeZone::Local::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 #------------------------------------------------------------------------------
33  
34 54 our $VERSION = '0.14'; # VERSION
35  
36 #------------------------------------------------------------------------------
37  
38 54 with qw( Pinto::Role::Plated );
39  
40 #------------------------------------------------------------------------------
41  
42 has root => (
43 is => 'ro',
44 isa => Dir,
45 default => $ENV{PINTO_REPOSITORY_ROOT},
46 54 coerce => 1,
47 );
48  
49 has repo => (
50 is => 'ro',
51 isa => 'Pinto::Repository',
52 276 ▶ default => sub { Pinto::Repository->new( root => $_[0]->root ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 54 lazy => 1,
54 );
55  
56 #------------------------------------------------------------------------------
57  
58 290 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
59 290 my $orig = shift;
60 290 my $class = shift;
61 290 my $args = $class->$orig(@_);
62  
63 # Grrr. Gotta avoid passing undefs to Moose
64 290 my @chrome_attrs = qw(verbose quiet color);
65 0 my %chrome_args = map { $_ => delete $args->{$_} }
66 290 grep { exists $args->{$_} } @chrome_attrs;
67  
68 290 ▶ $args->{chrome} ||= Pinto::Chrome::Term->new(%chrome_args);
Condition66%2/3
$args->{"chrome"} ||= "Pinto::Chrome::Term"->new(%chrome_args)
l!l&&r!l&&!r
802100
MC/DC0%0/2
$args->{"chrome"} ||= "Pinto::Chrome::Term"->new(%chrome_args)
$args->{"chrome"} "Pinto::Chrome::Term"->new(%chrome_args)
Truth table66%2/3
A ||= B
A= $args->{"chrome"}B= "Pinto::Chrome::Term"->new(%chrome_args)
ABresult
1X1
011
000
69  
70 290 return $args;
71 54 };
72  
73 #------------------------------------------------------------------------------
74  
75 205 ▶sub run {
Subroutine run: called CC=3 SCAR=11.0
Pod undocumented
76 205 my ( $self, $action_name, @action_args ) = @_;
77  
78 # Divert all warnings through our chrome
79 205 ▶ local $SIG{__WARN__} = sub { $self->warning($_) for @_ };
Subroutine __ANON__: called CC=2 SCAR=6.9
80  
81 # Convert hash refs to plain hash
82 205 ▶ @action_args = %{$action_args[0]} if @action_args == 1 and ref $action_args[0];
Branch: 1 branch
BranchTrueFalseTotal
if @action_args == 1 and ref $action_args[0] 2 203 205
Condition66%2/3
@action_args == 1 and ref $action_args[0]
!ll&&!rl&&r
20302
MC/DC50%1/2
@action_args == 1 and ref $action_args[0]
@action_args == 1 ref $action_args[0]
Truth table66%2/3
A and B
A= @action_args == 1B= ref $action_args[0]
ABresult
0X0
100
111
83  
84 205 ▶ my $result = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
85  
86 205 $self->repo->assert_sanity_ok;
87 205 $self->repo->assert_version_ok;
88  
89 205 my $action = $self->create_action( $action_name => @action_args );
90  
91 198 $self->repo->lock( $action->lock_type );
92  
93 195 $action->execute;
94 }
95 83 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
96 83 $self->repo->unlock;
97 83 $self->error($_);
98  
99 83 Pinto::Result->new->failed( because => $_ );
100 }
101 205 ▶ finally {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 205 $self->repo->unlock;
103 205 };
104  
105 205 return $result;
106 }
107  
108 #------------------------------------------------------------------------------
109  
110 205 ▶sub create_action {
Subroutine create_action: called CC=1 SCAR=0.0
Pod undocumented
111 205 my ( $self, $action_name, %action_args ) = @_;
112  
113 205 @action_args{qw(chrome repo)} = ( $self->chrome, $self->repo );
114 205 my $action_class = $self->load_class_for_action( name => $action_name );
115 204 my $action = $action_class->new(%action_args);
116  
117 198 return $action;
118 }
119  
120 #------------------------------------------------------------------------------
121  
122 205 ▶sub load_class_for_action {
Subroutine load_class_for_action: called CC=2 SCAR=7.2
Pod undocumented
123 205 my ( $self, %args ) = @_;
124  
125 205 ▶ my $action_name = ucfirst( $args{name} || throw 'Must specify an action name' );
Condition33%1/3
$args{'name'} || throw('Must specify an action name')
l!l&&r!l&&!r
20500
MC/DC0%0/2
$args{'name'} || throw('Must specify an action name')
$args{'name'} throw('Must specify an action name')
Truth table33%1/3
A || B
A= $args{'name'}B= throw('Must specify an action name')
ABresult
1X1
011
000
126 205 my $action_class = "Pinto::Action::$action_name";
127  
128 205 Class::Load::load_class($action_class);
129  
130 204 return $action_class;
131 }
132  
133 #------------------------------------------------------------------------------
134  
135 54 __PACKAGE__->meta->make_immutable;
136  
137 #-----------------------------------------------------------------------------
138  
139 54 1;
140  
141 __END__
« blib/lib/App/Pinto/Command/unregister.pm ↑ Summary blib/lib/Pinto/Action/Nop.pm »