Maker/Command/dependencies.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 95.8% 70 / 73 CC 7 SCAR 11.0
CC
7
Cov
95%
execute
6.0
validate_args
2.0
BEGIN
1.0
CRAP 3.0
« Maker/Command/build.pm ↑ Summary Maker/Command/sopmtest.pm »
1 package OPM::Maker::Command::dependencies;
2 21 $OPM::Maker::Command::dependencies::VERSION = '1.17';
3 # ABSTRACT: List dependencies of OTRS packages
4  
5 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 ▶use OPM::Maker -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use OPM::Maker::Utils qw(reformat_size check_args_sopm);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub abstract {
Subroutine abstract: called CC=1 SCAR=0.0
Pod documented
15 1 return "list dependencies for OPM packages";
16 }
17  
18 1 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
19 1 return "opmbuild dependencies <path_to_sopm_or_opm>";
20 }
21  
22 18 ▶sub validate_args {
Subroutine validate_args: called CC=2 SCAR=6.9
Pod documented
23 18 my ($self, $opt, $args) = @_;
24  
25 18 my $sopm = check_args_sopm( $args, 1 );
26 18 ▶ $self->usage_error( 'need path to .sopm or .opm' ) if
Branch: 1 branch
BranchTrueFalseTotal
if not $sopm 10 8 18
27 !$sopm;
28 }
29  
30 12 ▶sub execute {
Subroutine execute: called CC=6 SCAR=18.0
Pod documented
31 12 my ($self, $opt, $args) = @_;
32
33 12 my $file = check_args_sopm( $args, 1 );
34  
35 12 my %opts;
36 12 ▶ if ( !$ENV{OPM_UNSECURE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"OPM_UNSECURE"}) 12 0 12
37 12 %opts = (
38 no_network => 1,
39 expand_entities => 0,
40 );
41 }
42  
43 12 my $size = -s $file;
44  
45 # if file is big, but not "too big"
46 12 my $max_size = 31_457_280;
47 12 ▶ if ( $ENV{OPM_MAX_SIZE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"OPM_MAX_SIZE"}) 7 5 12
48 7 $max_size = reformat_size( $ENV{OPM_MAX_SIZE} );
49 }
50  
51 12 ▶ if ( $size > $max_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $max_size) 3 9 12
52 3 croak "$file too big (max size: $max_size bytes)";
53 }
54  
55 9 ▶ if ( $size > 10_000_000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 10000000) 0 9 9
56 0 $opts{huge} = 1;
57 }
58  
59 9 my $parser = XML::LibXML->new( %opts );
60 9 my $tree = $parser->parse_file( $file );
61
62 9 my $root_elem = $tree->getDocumentElement;
63  
64 # retrieve file information
65 9 my @package_req = $root_elem->findnodes( 'PackageRequired' );
66 9 my @modules_req = $root_elem->findnodes( 'ModuleRequired' );
67
68 9 my %labels = (
69 PackageRequired => 'OPM package',
70 ModuleRequired => 'CPAN module',
71 );
72
73 DEP:
74 9 for my $dependency ( @package_req, @modules_req ) {
75 14 my $type = $dependency->nodeName;
76 14 my $version = $dependency->findvalue( '@Version' );
77 14 my $name = $dependency->textContent;
78
79 14 print "$name - $version (" . $labels{$type} . ")\n";
80 }
81 }
82  
83 21 1;
84  
85 __END__
« Maker/Command/build.pm ↑ Summary Maker/Command/sopmtest.pm »