Magpie/Action/Old.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Magpie/Action/Missing.pm ↑ Summary Magpie/URPM.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::Old;
14 # ABSTRACT: old command implementation
15 $App::Magpie::Action::Old::VERSION = '2.010';
16 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶use App::Magpie::Action::Old::Module;
Subroutine BEGIN: called CC=1 SCAR=2.6
20 use App::Magpie::Action::Old::Set;
21  
22 with 'App::Magpie::Role::Logging';
23 with 'App::Magpie::Role::RunningCommand';
24  
25  
26  
27 sub run {
28 my ($self) = @_;
29 my %category;
30  
31 my $outfile = path( "/tmp/cpan-o.stdout" );
32 if ( $ENV{MAGPIE_REUSE_CPAN_O_OUTPUT} ) {
33 $self->log( "re-using cpan -O output from $outfile" );
34 } else {
35 my $cmd = "cpan -O >$outfile 2>/tmp/cpan-o.stderr";
36 $self->log( "running: $cmd" );
37 system("$cmd") == 0
38 or $self->log_fatal( "command [$cmd] exited with value " . ($?>>8) );
39 }
40 my @lines = $outfile->lines;
41  
42 # A file where will we store ignored / rejected lines from cpan -O
43 # output
44 my $rejfh = path( "/tmp/cpan-o.rej" )->openw;
45 my $noline = 0;
46  
47 # analyze "cpan -O" output - meaningful lines are of the form:
48 # DBIx::Class::Helper::ResultSet::Shortcut::Columns 2.0160 2.0170
49 LINE:
50 foreach my $line ( @lines ) {
51 $noline++;
52 if ( $line !~ /
53 ^ # begins with
54 (\S+) # anything non-whitespace (module name)
55 \s+ # followed by some spaces
56 ( # followed by an alternative
57 v?(?:\d\S+) # either sthg beginning with a digit (prefixed with optional v)
58 |
59 undef # or litteral undef
60 )
61 \s+ # followed by some spaces
62 ( # followed by an alternative
63 v?(?:\d\S+) # either sthg beginning with a digit (prefixed with optional v)
64 |
65 undef # or litteral undef
66 )
67 $ # and an end of line
68 /x ) {
69 $rejfh->print( "$noline:$line" );
70 next;
71 }
72 my ($modname, $oldver, $newver) = ($1,$2,$3);
73 my $module = App::Magpie::Action::Old::Module->new(
74 name => $modname, oldver => $oldver, newver => $newver );
75  
76 my $category = $module->category;
77 $category{ $category } //= App::Magpie::Action::Old::Set->new(name=>$category);
78 $category{ $category }->add_module( $module );
79 }
80  
81 return values %category;
82 }
83  
84  
85  
86 1;
87  
88 __END__
« Magpie/Action/Missing.pm ↑ Summary Magpie/URPM.pm »