File Coverage

blib/lib/RPM/Query/Capability.pm
Criterion Covered Total %
statement 9 36 25.0
branch 0 16 0.0
condition n/a
subroutine 3 10 30.0
pod 6 6 100.0
total 18 68 26.4


line stmt bran cond sub pod time code
1             package RPM::Query::Capability;
2 5     5   30 use strict;
  5         9  
  5         123  
3 5     5   21 use warnings;
  5         7  
  5         116  
4 5     5   20 use base qw{Package::New};
  5         9  
  5         2189  
5              
6             our $VERSION = '0.02';
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             sub capability_name {
35 0     0 1   my $self = shift;
36 0 0         $self->{'capability_name'} = shift if @_;
37 0 0         die("Error: capability_name property required") unless $self->{'capability_name'};
38 0           return $self->{'capability_name'};
39             }
40              
41             sub _capability_name {
42 0     0     my $self = shift;
43 0 0         unless (defined $self->{'_capability_name'}) {
44 0           my $hash = {};
45 0 0         if ($self->capability_name =~ m/\A(.*)\s+(>=|<=|=)\s+(.*)\Z/) {
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     0 1   sub name {shift->_capability_name->{'name'}};
64              
65             =head2 version
66              
67             =cut
68              
69 0     0 1   sub version {shift->_capability_name->{'version'}};
70              
71             =head2 package
72              
73             Returns the first package (alphabetically) that provides this capability
74              
75             =cut
76              
77 0     0 1   sub package {shift->whatprovides->[0]};
78              
79             =head2 whatprovides
80              
81             Returns a list of package objects that provides this capability.
82              
83             =cut
84              
85             sub whatprovides {
86 0     0 1   my $self = shift;
87 0 0         unless ($self->{'whatprovides'}) {
88 0 0         $self->{'whatprovides'} = $self->parent->whatprovides($self->name) or die("Error: package not found");
89             }
90 0           return $self->{'whatprovides'};
91             }
92              
93             =head1 ACCESSORS
94              
95             =head2 parent
96              
97             =cut
98              
99             sub parent {
100 0     0 1   my $self = shift;
101 0 0         $self->{'parent'} = shift if @_;
102 0 0         $self->{'parent'} = RPM::Query->new unless $self->{'parent'};
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             1;