File Coverage

blib/lib/JSAN/Index/Release/Source.pm
Criterion Covered Total %
statement 38 38 100.0
branch 7 10 70.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 53 56 94.6


line stmt bran cond sub pod time code
1             package JSAN::Index::Release::Source;
2              
3 6     6   36 use strict;
  6         11  
  6         204  
4 6     6   35 use Algorithm::Dependency::Item ();
  6         12  
  6         161  
5 6     6   32 use Algorithm::Dependency::Source ();
  6         11  
  6         186  
6              
7 6     6   41 use vars qw{$VERSION @ISA};
  6         10  
  6         401  
8             BEGIN {
9 6     6   14 $VERSION = '0.28';
10 6         2110 @ISA = 'Algorithm::Dependency::Source';
11             }
12              
13             sub new {
14 6 50   6 1 5076 my $class = ref $_[0] ? ref shift : shift;
15 6         26 my %params = @_;
16              
17             # Create the basic object
18 6         78 my $self = $class->SUPER::new();
19              
20             # Set the methods to use
21 6         127 $self->{requires_releases} = 1;
22 6 100       34 if ( $params{build} ) {
23 1         3 $self->{build_requires_releases} = 1;
24             }
25              
26 6         36 $self;
27             }
28              
29             sub _load_item_list {
30 6     6   1239 my $self = shift;
31              
32             ### FIXME: This is crudely effective, but a little innefficient.
33             ### Later, we should be able to determine which subset of
34             ### these can never be called, and leave them out of the list.
35              
36             # Get every single release in the index
37 6         42 my @releases = JSAN::Index::Release->retrieve_all;
38              
39             # Wrap the releases in the Adapter objects
40 6         86 my @items = ();
41 6         24 foreach my $release ( @releases ) {
42 2142         9969 my $id = $release->source;
43              
44             # Get the list of dependencies
45 2142         4193 my @depends = ();
46 2142 50       7103 if ( $self->{requires_releases} ) {
47 2142         7184 push @depends, $release->requires_releases;
48             }
49 2142 100       8367 if ( $self->{build_requires_releases} ) {
50 357         1743 push @depends, $release->build_requires_releases;
51             }
52              
53             # Convert to a distinct source list
54 2142         4660 my %seen = ();
55 2142         4536 @depends = grep { ! $seen{$_} } map { $_->source } @depends;
  600         3494  
  600         2378  
56              
57             # Add the dependency
58 2142 50       13357 my $item = Algorithm::Dependency::Item->new( $id => @depends )
59             or die "Failed to create Algorithm::Dependency::Item";
60 2142         43967 push @items, $item;
61             }
62              
63 6         4463 \@items;
64             }
65              
66             1;