File Coverage

blib/lib/Algorithm/Dependency/Source/HoA.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 8 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 38 42 90.5


line stmt bran cond sub pod time code
1             package Algorithm::Dependency::Source::HoA;
2              
3             =pod
4            
5             =head1 NAME
6            
7             Algorithm::Dependency::Source::HoA - Source for a HASH of ARRAYs
8            
9             =head1 SYNOPSIS
10            
11             # The basic data structure
12             my $deps = {
13             foo => [ 'bar', 'baz' ],
14             bar => [],
15             baz => [ 'bar' ],
16             };
17            
18             # Create the source from it
19             my $Source = Algorithm::Dependency::Source::HoA->new( $deps );
20            
21             =head1 DESCRIPTION
22            
23             C<Algorithm::Dependency::Source::HoA> implements a
24             L<source|Algorithm::Dependency::Source> where the items names are provided
25             in the most simple form, a reference to a C<HASH> of C<ARRAY> references.
26            
27             =head1 METHODS
28            
29             This documents the methods differing from the ordinary
30             L<Algorithm::Dependency::Source> methods.
31            
32             =cut
33              
34 3     3   38 use strict;
  3         61  
  3         50  
35 3     3   786 use base 'Algorithm::Dependency::Source';
  3         32  
  3         52  
36 3     3   231 use Params::Util qw{_HASH _ARRAY0};
  3         29  
  3         56  
37              
38 3     3   79 use vars qw{$VERSION};
  3         28  
  3         93  
39             BEGIN {
40 3     3   42 $VERSION = '1.102';
41             }
42              
43              
44              
45              
46              
47             #####################################################################
48             # Constructor
49              
50             =pod
51            
52             =head2 new $filename
53            
54             When constructing a new C<Algorithm::Dependency::Source::HoA> object, an
55             argument should be provided of a reference to a HASH of ARRAY references,
56             containing the names of other HASH elements.
57            
58             Returns the object, or C<undef> if the structure is not correct.
59            
60             =cut
61              
62             sub new {
63 1     1 1 9 my $class = shift;
64 1 50       14 my $hash = _HASH(shift) or return undef;
65 1         29 foreach my $deps ( values %$hash ) {
66 6 50       96 _ARRAY0($deps) or return undef;
67             }
68              
69             # Get the basic source object
70 1 50       39 my $self = $class->SUPER::new() or return undef;
71              
72             # Add our arguments
73 1         10 $self->{hash} = $hash;
74              
75 1         11 $self;
76             }
77              
78              
79              
80              
81              
82             #####################################################################
83             # Private Methods
84              
85             sub _load_item_list {
86 1     1   11 my $self = shift;
87              
88             # Build the item objects from the data
89 1         9 my $hash = $self->{hash};
90 6         86 my @items = map {
91 1 50       16 Algorithm::Dependency::Item->new( $_, @{$hash->{$_}} )
  6         242  
92             or return undef;
93             } keys %$hash;
94              
95 1         20 \@items;
96             }
97              
98             1;
99              
100             =pod
101            
102             =head1 SUPPORT
103            
104             To file a bug against this module, use the CPAN bug tracking system
105            
106             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-Dependency>
107            
108             For other comments, contact the author.
109            
110             =head1 AUTHOR
111            
112             Adam Kennedy, L<http://ali.as/>, cpan@ali.as
113            
114             =head1 SEE ALSO
115            
116             L<Algorithm::Dependency>, L<Algorithm::Dependency::Source>
117            
118             =head1 COPYRIGHT
119            
120             Copyright (c) 2003 - 2005 Adam Kennedy. All rights reserved.
121            
122             This program is free software; you can redistribute
123             it and/or modify it under the same terms as Perl itself.
124            
125             The full text of the license can be found in the
126             LICENSE file included with this module.
127            
128             =cut
129