Query/Capability.pm

filter: Statementstmt 28.9% 11 / 38 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 100% 6 / 6 totaltotal 28.5% 20 / 70 CC 9 SCAR 21.4
CC
9
Cov
20%
capability_name
12.0
_capability_name
12.0
whatprovides
12.0
CRAP 8.5
« Query.pm ↑ Summary Query/Package.pm »
1 package RPM::Query::Capability;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use base qw{Package::New};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = '0.05';
7  
8 =head1 NAME
9  
10 RPM::Query - Perl object overlay of an RPM capability
11  
12 =head1 SYNOPSIS
13  
14 use RPM::Query;
15 my $rpm = RPM::Query->new;
16 my $capabilities = $rpm->requires('perl'); #isa ARRAY of RPM::Query::Capability
17 foreach my $capability (@$capabilities) {
18 printf "%s - %s\n", $capability->name, $capability->package->name;
19 }
20  
21 =head1 DESCRIPTION
22  
23 =head1 METHODS
24  
25 =head2 capability_name
26  
27 Returns the capability name with optional version as returns by the rpm command.
28  
29 perl(Scalar::Util) >= 1.10
30 perl(strict)
31  
32 =cut
33  
34 0 ▶sub capability_name {
Subroutine capability_name: not called CC=3 SCAR=24.8
Pod documented
35 0 my $self = shift;
36 0 ▶ $self->{'capability_name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
37 0 ▶ die("Error: capability_name property required") unless $self->{'capability_name'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"capability_name"} 0 0 0
38 0 return $self->{'capability_name'};
39 }
40  
41 0 ▶sub _capability_name {
Subroutine _capability_name: not called CC=3 SCAR=24.8
42 0 my $self = shift;
43 0 ▶ unless (defined $self->{'_capability_name'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_capability_name"}) 0 0 0
44 0 my $hash = {};
45 0 ▶ if ($self->capability_name =~ m/\A(.*)\s+(>=|<=|=)\s+(.*)\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->capability_name =~ /\A(.*)\s+(>=|<=|=)\s+(.*)\Z/) { } 0 0 0
46 0 $hash->{'name'} = $1;
47 0 $hash->{'compare'} = $2;
48 0 $hash->{'version'} = $3;
49 } else {
50 0 $hash->{'name'} = $self->capability_name;
51 0 $hash->{'version'} = '';
52 0 $hash->{'compare'} = undef;
53 }
54 0 $self->{'_capability_name'} = $hash;
55 }
56 0 return $self->{'_capability_name'};
57 }
58  
59 =head2 name
60  
61 =cut
62  
63 0 ▶sub name {shift->_capability_name->{'name'}};
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
64  
65 =head2 version
66  
67 =cut
68  
69 0 ▶sub version {shift->_capability_name->{'version'}};
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
70  
71 =head2 package
72  
73 Returns the first package (alphabetically) that provides this capability
74  
75 =cut
76  
77 0 ▶sub package {shift->whatprovides->[0]};
Subroutine package: not called CC=1 SCAR=6.9
Pod documented
78  
79 =head2 whatprovides
80  
81 Returns a list of package objects that provides this capability.
82  
83 =cut
84  
85 0 ▶sub whatprovides {
Subroutine whatprovides: not called CC=3 SCAR=24.8
Pod documented
86 0 my $self = shift;
87 0 ▶ unless ($self->{'whatprovides'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"whatprovides"}) 0 0 0
88 0 ▶ $self->{'whatprovides'} = $self->parent->whatprovides($self->name) or die("Error: package not found");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"whatprovides"} = $self->parent->whatprovides($self->name) or die "Error: package not found" 0 0 0
89 }
90 0 return $self->{'whatprovides'};
91 }
92  
93 =head1 ACCESSORS
94  
95 =head2 parent
96  
97 =cut
98  
99 0 ▶sub parent {
Subroutine parent: not called CC=3 SCAR=24.8
Pod documented
100 0 my $self = shift;
101 0 ▶ $self->{'parent'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
102 0 ▶ $self->{'parent'} = RPM::Query->new unless $self->{'parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parent"} 0 0 0
103 0 return $self->{'parent'};
104 }
105  
106 =head1 SEE ALSO
107  
108 =head1 AUTHOR
109  
110 Michael R. Davis
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 MIT License
115  
116 Copyright (c) 2023 Michael R. Davis
117  
118 =cut
119  
120 5 1;
« Query.pm ↑ Summary Query/Package.pm »