Magpie/Action/Old/Module.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 94.2% 33 / 35 CC 1 SCAR 0.3
CC
1
Cov
92%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Magpie/Action/Recent.pm ↑ Summary Magpie/Action/WebStatic.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 2 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package App::Magpie::Action::Old::Module;
14 # ABSTRACT: module that has a newer version available
15 $App::Magpie::Action::Old::Module::VERSION = '2.010';
16 2 ▶use List::AllUtils qw{ each_array };
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use MooseX::Has::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use App::Magpie::Constants qw{ $SHAREDIR };
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 ▶use App::Magpie::URPM;
Subroutine BEGIN: called CC=1 SCAR=2.6
23  
24  
25 # -- private vars
26  
27 my (@SKIP_MOD_NAME, @SKIP_MOD_VERSION);
28 {
29 my $skipfile = $SHAREDIR->child( 'modules.skip' );
30 my @skips = $skipfile->lines;
31 foreach my $skip ( @skips ) {
32 next if $skip =~ /^#/;
33 chomp $skip;
34 my ($module, $version, $reason) = split /\s*;\s*/, $skip;
35 $version ||= ".*"; # no version: all versions are skipped
36 push @SKIP_MOD_NAME, qr/^$module$/;
37 push @SKIP_MOD_VERSION, qr/^$version$/;
38 }
39 }
40  
41 my %SKIPPKG = do {
42 my $skipfile = $SHAREDIR->child( 'packages.skip' );
43 my @skips = $skipfile->lines;
44 my %skip;
45 foreach my $skip ( @skips ) {
46 next if $skip =~ /^#/;
47 chomp $skip;
48 my ($pkg, $reason) = split /\s*;\s*/, $skip;
49 $skip{$pkg} = 1;
50 }
51 %skip;
52 };
53  
54  
55 # -- public attributes
56  
57  
58 has name => ( ro, isa => "Str", required );
59 has oldver => ( ro, isa => "Str" );
60 has newver => ( ro, isa => "Str" );
61 has is_core => ( rw, isa => "Bool" );
62 has packages => ( ro, isa => "ArrayRef", lazy_build, auto_deref );
63  
64 sub _build_packages {
65 my ($self) = @_;
66 my $urpm = App::Magpie::URPM->instance;
67 my $module = $self->name;
68 my %seen; # to remove packages in both i586 & x86_64 medias
69 my @pkgs =
70 grep { ! $seen{ $_->name }++ }
71 $urpm->packages_providing( $module );
72  
73 my $iscore = scalar( grep { $_->name =~ /^perl(-base)?$/ } @pkgs );
74 $self->set_is_core( !!$iscore );
75 return [ grep { $_->name !~ /^perl(-base)?$/ } @pkgs ];
76 }
77  
78  
79 # -- public methods
80  
81  
82 sub category {
83 my ($self) = @_;
84 my @pkgs = $self->packages;
85 my $iscore = $self->is_core;
86  
87 return "ignored" if $self->is_ignored;
88  
89 if ( $iscore ) {
90 return "core" if scalar(@pkgs) == 0;
91 return "strange" if scalar(@pkgs) >= 2;
92 # scalar(@pkgs) == 1;
93 return "ignored" if exists $SKIPPKG{ $pkgs[0] };
94 return "dual-lifed";
95 }
96  
97 return "orphan" if scalar(@pkgs) == 0;
98 return "strange" if scalar(@pkgs) >= 2;
99 # scalar(@pkgs) == 1;
100 return "ignored" if exists $SKIPPKG{ $pkgs[0]->name };
101 return "null_old" if $self->oldver eq "0" || $self->oldver eq "undef";
102 return "null_new" if $self->newver eq "0" || $self->newver eq "undef";
103 return "nodiff" if $self->oldver eq $self->newver; # cpan can be confused
104 return "unparsable" if $self->oldver eq "Unparsable";
105 return "normal";
106 }
107  
108  
109  
110 sub is_ignored {
111 my $self = shift;
112  
113 # check if module is ignored, regex comparison
114 my $it = each_array @SKIP_MOD_NAME, @SKIP_MOD_VERSION;
115 while ( my ($mod, $ver) = $it->() ) {
116 return 1 if $self->name =~ $mod && $self->newver =~ $ver;
117 }
118  
119 return 0;
120 }
121  
122  
123 __PACKAGE__->meta->make_immutable;
124 1;
125  
126 __END__
« Magpie/Action/Recent.pm ↑ Summary Magpie/Action/WebStatic.pm »