File Coverage

blib/lib/CPAN/ReverseDependencies.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 2 100.0
condition n/a
subroutine 9 9 100.0
pod 0 1 0.0
total 43 44 97.7


line stmt bran cond sub pod time code
1             package CPAN::ReverseDependencies;
2             # ABSTRACT: given a CPAN dist name, find other CPAN dists that use it
3             $CPAN::ReverseDependencies::VERSION = '0.02';
4 3     3   141676 use 5.006;
  3         31  
5 3     3   21 use strict;
  3         12  
  3         64  
6 3     3   15 use warnings;
  3         16  
  3         95  
7 3     3   1760 use Moo;
  3         35413  
  3         17  
8 3     3   4490 use Carp;
  3         8  
  3         177  
9 3     3   1603 use MetaCPAN::Client;
  3         1071404  
  3         151  
10 3     3   36 use parent 'Exporter';
  3         8  
  3         34  
11              
12             our @EXPORT_OK = qw/ get_reverse_dependencies /;
13              
14             has ua => ( is => 'lazy' );
15              
16             sub _build_ua
17             {
18 1     1   20 return MetaCPAN::Client->new;
19             }
20              
21             sub get_reverse_dependencies
22             {
23 2     2 0 1970 my $distname = pop @_;
24 2         5 my $ua;
25              
26 2 100       9 if (@_ == 1) {
27 1         2 my $self = shift;
28 1         30 $ua = $self->ua;
29             }
30             else {
31 1         11 $ua = MetaCPAN::Client->new();
32             }
33 2         7862 my $resultset = $ua->reverse_dependencies($distname);
34 2         894723 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         10 while (my $release = $resultset->next) {
41 40         20459 push(@dependents, $release->distribution);
42             }
43              
44 2         131 return @dependents;
45             }
46              
47             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 exports a single function,
62             C,
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 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 directly,
71             and get the info you need from the L
72             objects returned by the C method.
73              
74             This module will C 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
99              
100             =head1 AUTHOR
101              
102             Neil Bowers Eneilb@cpan.orgE
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2014 by Neil Bowers .
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