blib/lib/CPAN/ReverseDependencies.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 98.0% 49 / 50 SCAR 11.0
CC
3
Cov
100%
get_reverse_dependencies
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package CPAN::ReverseDependencies;
2 # ABSTRACT: given a CPAN dist name, find other CPAN dists that use it
3 3 $CPAN::ReverseDependencies::VERSION = '0.02';
4 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use MetaCPAN::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our @EXPORT_OK = qw/ get_reverse_dependencies /;
13  
14 3 has ua => ( is => 'lazy' );
15  
16 sub _build_ua
17 {
18 1 ▶ return MetaCPAN::Client->new;
Subroutine _build_ua: called CC=1 SCAR=0.0
19 }
20  
21 sub get_reverse_dependencies
22 {
23 2 ▶ my $distname = pop @_;
Subroutine get_reverse_dependencies: called CC=3 SCAR=11.0
Pod undocumented
24 2 my $ua;
25  
26 2 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 1 1 2
27 1 my $self = shift;
28 1 $ua = $self->ua;
29 }
30 else {
31 1 $ua = MetaCPAN::Client->new();
32 }
33 2 my $resultset = $ua->reverse_dependencies($distname);
34 2 my @dependents;
35  
36 # If you want more than just the names of
37 # the dependent distributions, take this loop
38 # and look at the doc of MetaCPAN::Client::Release
39 # to see what other information is easily available
40 2 ▶ while (my $release = $resultset->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $release = $resultset->next) 36 2 38
41 36 push(@dependents, $release->distribution);
42 }
43  
44 2 return @dependents;
45 }
46  
47 3 1;
48  
49 =head1 NAME
50  
51 CPAN::ReverseDependencies - given a CPAN dist name, find other CPAN dists that use it
52  
53 =head1 SYNOPSIS
54  
55 use CPAN::ReverseDependencies qw/ get_reverse_dependencies /;
56  
57 my @deps = get_reverse_dependencies('Module-Path');
58  
59 =head1 DESCRIPTION
60  
61 B<CPAN::ReverseDependencies> exports a single function,
62 C<get_reverse_dependencies>,
63 which takes the name of a CPAN distribution and
64 returns a list containing names of other CPAN distributions that have declared
65 a dependence on the specified distribution.
66  
67 It uses L<MetaCPAN::Client> to look up the reverse dependencies,
68 so obviously you have to be online for this module to work.
69 If you want more than just the name of the dependent distributions,
70 use L<MetaCPAN::Client> directly,
71 and get the info you need from the L<MetaCPAN::Client::Release>
72 objects returned by the C<reverse_dependencies> method.
73  
74 This module will C<croak> in a number of situations:
75  
76 =over 4
77  
78 =item * If you request reverse dependencies for a non-existent distribution;
79  
80 =item * If you're not online;
81  
82 =item * If there's a problem with MetaCPAN itself.
83  
84 =back
85  
86 =head2 OO Interface
87  
88 The first release had an OO interface, which is supported for backwards compatibility:
89  
90 use CPAN::ReverseDependencies;
91
92 my $revua = CPAN::ReverseDependencies->new();
93 my @deps = $revua->get_reverse_dependencies('Module-Path');
94  
95  
96 =head1 REPOSITORY
97  
98 L<https://github.com/neilb/CPAN-ReverseDependencies>
99  
100 =head1 AUTHOR
101  
102 Neil Bowers E<lt>neilb@cpan.orgE<gt>
103  
104 =head1 COPYRIGHT AND LICENSE
105  
106 This software is copyright (c) 2014 by Neil Bowers <neilb@cpan.org>.
107  
108 This is free software; you can redistribute it and/or modify it under
109 the same terms as the Perl 5 programming language system itself.
110  
111 =cut
112  
↑ Summary