File Coverage

blib/lib/Algorithm/Dependency/Source/HoA.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 8 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 35 39 89.7


line stmt bran cond sub pod time code
1             package Algorithm::Dependency::Source::HoA;
2             # ABSTRACT: Source for a HASH of ARRAYs
3              
4             #pod =pod
5             #pod
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod # The basic data structure
9             #pod my $deps = {
10             #pod foo => [ 'bar', 'baz' ],
11             #pod bar => [],
12             #pod baz => [ 'bar' ],
13             #pod };
14             #pod
15             #pod # Create the source from it
16             #pod my $Source = Algorithm::Dependency::Source::HoA->new( $deps );
17             #pod
18             #pod =head1 DESCRIPTION
19             #pod
20             #pod C implements a
21             #pod L where the items names are provided
22             #pod in the most simple form, a reference to a C of C references.
23             #pod
24             #pod =head1 METHODS
25             #pod
26             #pod This documents the methods differing from the ordinary
27             #pod L methods.
28             #pod
29             #pod =cut
30              
31 3     3   1912 use 5.005;
  3         10  
32 3     3   15 use strict;
  3         7  
  3         58  
33 3     3   14 use Algorithm::Dependency::Source ();
  3         4  
  3         52  
34 3     3   24 use Params::Util qw{_HASH _ARRAY0};
  3         7  
  3         847  
35              
36             our $VERSION = '1.112';
37             our @ISA = 'Algorithm::Dependency::Source';
38              
39              
40             #####################################################################
41             # Constructor
42              
43             #pod =pod
44             #pod
45             #pod =head2 new $filename
46             #pod
47             #pod When constructing a new C object, an
48             #pod argument should be provided of a reference to a HASH of ARRAY references,
49             #pod containing the names of other HASH elements.
50             #pod
51             #pod Returns the object, or C if the structure is not correct.
52             #pod
53             #pod =cut
54              
55             sub new {
56 1     1 1 118 my $class = shift;
57 1 50       8 my $hash = _HASH(shift) or return undef;
58 1         5 foreach my $deps ( values %$hash ) {
59 6 50       15 _ARRAY0($deps) or return undef;
60             }
61              
62             # Get the basic source object
63 1 50       24 my $self = $class->SUPER::new() or return undef;
64              
65             # Add our arguments
66 1         3 $self->{hash} = $hash;
67              
68 1         3 $self;
69             }
70              
71              
72              
73              
74              
75             #####################################################################
76             # Private Methods
77              
78             sub _load_item_list {
79 1     1   3 my $self = shift;
80              
81             # Build the item objects from the data
82 1         2 my $hash = $self->{hash};
83             my @items = map {
84 1 50       5 Algorithm::Dependency::Item->new( $_, @{$hash->{$_}} )
  6         11  
  6         19  
85             or return undef;
86             } keys %$hash;
87              
88 1         6 \@items;
89             }
90              
91             1;
92              
93             __END__