VersionRange/App.pm

filter: Statementstmt 67.5% 50 / 74 Branchbran 35.7% 10 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 100% 2 / 2 totaltotal 62.9% 73 / 116 CC 17 SCAR 38.1
CC
17
Cov
59%
run
74.0
cli_error
2.0
BEGIN
1.0
CRAP 45.4
« PackageURL/App.pm ↑ Summary PackageURL/Type.pm »
1 package URI::VersionRange::App;
2  
3 2 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Getopt::Long qw(GetOptionsFromArray :config gnu_compat);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use URI::VersionRange ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = '2.26';
17  
18 0 ▶sub cli_error {
Subroutine cli_error: not called CC=1 SCAR=6.9
Pod documented
19 0 my ($error) = @_;
20 0 $error =~ s/ at .* line \d+.*//;
21 0 print STDERR "ERROR: $error\n";
22 }
23  
24 1 ▶sub run {
Subroutine run: called CC=17 SCAR=43.0
Pod documented
25  
26 1 my ($class, @args) = @_;
27  
28 # UTF-8 encoded command line arguments
29 1 utf8::decode($_) for @args;
30  
31 1 my %options = (format => 'json');
32  
33 1 ▶ GetOptionsFromArray(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, \%options, ("help", "man", "v", "contains=s", "null|0", "format=s", "json", "human-readable|h")) or pod2usage("-verbose", 0) 1 0 1
34 \@args, \%options, qw(
35 help
36 man
37 v
38  
39 contains=s
40  
41 null|0
42 format=s
43  
44 json
45 human-readable|h
46 )
47 ) or pod2usage(-verbose => 0);
48  
49 1 ▶ pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"man"} 0 1 1
50 1 ▶ pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"help"} 0 1 1
51  
52 1 ▶ if (defined $options{v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"v"}) 0 1 1
53  
54 0 (my $progname = $0) =~ s/.*\///;
55  
56 0 say <<"VERSION";
57 $progname version $URI::VersionRange::VERSION
58  
59 Copyright 2022-2026, Giuseppe Di Terlizzi <gdt\@cpan.org>
60  
61 This program is part of the "URI-PackageURL" distribution and is free software;
62 you can redistribute it and/or modify it under the same terms as Perl itself.
63  
64 Complete documentation for $progname can be found using 'man $progname'
65 or on the internet at <https://metacpan.org/dist/URI-PackageURL>.
66 VERSION
67  
68 0 return 0;
69  
70 }
71  
72 1 my ($vers_string) = @args;
73  
74 1 ▶ pod2usage(-verbose => 1) if !$vers_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $vers_string 0 1 1
75  
76 1 ▶ $options{format} = 'json' if defined $options{json};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"json"} 1 0 1
77 1 ▶ $options{format} = 'human-readable' if defined $options{'human-readable'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"human-readable"} 0 1 1
78  
79 1 my $vers = eval { URI::VersionRange->from_string($vers_string) };
80  
81 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
82 0 cli_error($@);
83 0 return 1;
84 }
85  
86 1 ▶ if (defined $options{contains}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"contains"}) 0 1 1
87  
88 0 my $vers_comparator_class = join '::', 'URI::VersionRange::Version', $vers->scheme;
89  
90 0 ▶ if (URI::VersionRange::Version->load($vers->scheme) eq 'URI::VersionRange::Version') {
Branch: 1 branch
BranchTrueFalseTotal
if ("URI::VersionRange::Version"->load($vers->scheme) eq "URI::VersionRange::Version") 0 0 0
91 0 say STDERR 'WARNING: Loaded the fallback scheme class comparator.';
92 0 say STDERR ' The comparison may not work correctly!';
93 }
94  
95 0 my $res = eval { $vers->contains($options{contains}) };
96  
97 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
98 0 cli_error($@);
99 0 return 1;
100 }
101  
102 0 ▶ say STDERR $res ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 0 0 0
103 0 return !$res;
104  
105 }
106  
107 1 ▶ if ($options{format} eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"format"} eq "json") 1 0 1
108 1 print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($vers);
109 1 return 0;
110 }
111  
112 0 ▶ if ($options{format} eq 'human-readable') {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"format"} eq "human-readable") 0 0 0
113 0 say $vers->scheme;
114 0 say "- " . $_->to_human_string for (@{$vers->constraints});
115 0 return 0;
116 }
117  
118 }
119  
120 2 1;
121  
122 __END__
« PackageURL/App.pm ↑ Summary PackageURL/Type.pm »