Magpie/Action/DWIM.pm

filter: Statementstmt 90.0% 18 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.5% 25 / 27 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Magpie/Action/Checkout.pm ↑ Summary Magpie/Action/Sort.pm »
1 #
2 # This file is part of App-Magpie
3 #
4 # This software is copyright (c) 2011 by Jerome Quelin.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 1 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package App::Magpie::Action::DWIM;
14 # ABSTRACT: dwim command implementation
15 $App::Magpie::Action::DWIM::VERSION = '2.010';
16 1 ▶use File::pushd;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Parallel::ForkManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶use App::Magpie::Action::Checkout;
Subroutine BEGIN: called CC=1 SCAR=2.6
21 use App::Magpie::Action::Old;
22 use App::Magpie::Action::Update;
23  
24 with 'App::Magpie::Role::Logging';
25  
26  
27  
28 sub run {
29 my ($self, $directory) = @_;
30
31 my @sets = App::Magpie::Action::Old->new->run;
32 my ($normal) = grep { $_->name eq "normal" } @sets;
33 if ( not defined $normal ) {
34 $self->log( "no package to update" );
35 return;
36 }
37 my @modules = $normal->all_modules;
38  
39 my $pm = Parallel::ForkManager->new(5);
40 my @failed;
41 $pm->run_on_finish( sub {
42 my ($pid, $rv, $id, $signal, $core, $data) = @_;
43 push @failed, $id if $rv;
44 print $data;
45 } );
46  
47 # loop around the modules
48 my %seen;
49 foreach my $module (@modules) {
50 my $pkg = ( $module->packages )[0];
51 my $modname = $module->name;
52 my $pkgname = $pkg->name;
53 next if $seen{$pkgname}++; # do not try to update a pkg more than once
54  
55 # forks and returns the pid for the child:
56 my $pid = $pm->start($pkgname) and next;
57  
58 $self->log( "updating " . $modname
59 . " from " . $module->oldver
60 . " to " . $module->newver
61 . " in " . $pkgname );
62  
63 # check out the package
64 my $pkgdir = App::Magpie::Action::Checkout->new->run( $pkg->name, $directory );
65 my $old = pushd( $pkgdir );
66  
67 # update the package
68 eval { App::Magpie::Action::Update->new->run; };
69 my $rv = $@ ? 1 : 0;
70 $pm->finish( $rv ); # Terminates the child process
71 }
72 $pm->wait_all_children;
73 $self->log( "error while updating: $_" ) for sort @failed;
74 }
75  
76  
77  
78 1;
79  
80 __END__
« Magpie/Action/Checkout.pm ↑ Summary Magpie/Action/Sort.pm »