File Coverage

blib/lib/Test/Data/Split/Backend/ValidateHash.pm
Criterion Covered Total %
statement 22 24 91.6
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 30 34 88.2


line stmt bran cond sub pod time code
1             package Test::Data::Split::Backend::ValidateHash;
2             $Test::Data::Split::Backend::ValidateHash::VERSION = '0.2.2';
3 2     2   26075 use strict;
  2         5  
  2         48  
4 2     2   8 use warnings;
  2         4  
  2         45  
5              
6 2     2   9 use Carp qw/confess/;
  2         3  
  2         72  
7              
8 2     2   17 use parent 'Test::Data::Split::Backend::Hash';
  2         4  
  2         20  
9              
10             sub populate
11             {
12 2     2 1 318 my ( $self, $array_ref ) = @_;
13              
14 2         6 my @l = @$array_ref;
15              
16 2         5 my $tests = $self->get_hash;
17              
18 2 50       11 if ( @l & 0x1 )
19             {
20 0         0 confess("Input length is not even.");
21             }
22 2         8 while (@l)
23             {
24 4         21 my $key = shift @l;
25 4         7 my $val = shift @l;
26 4 50       9 if ( exists( $tests->{$key} ) )
27             {
28 0         0 confess("Duplicate key '$key'!");
29             }
30 4         12 $tests->{$key} =
31             $self->validate_and_transform( { id => $key, data => $val, } );
32             }
33              
34 1         7 return;
35             }
36              
37             1;
38              
39             __END__
40              
41             =pod
42              
43             =encoding UTF-8
44              
45             =head1 NAME
46              
47             Test::Data::Split::Backend::ValidateHash - hash backend with input validation
48             and transformation.
49              
50             =head1 VERSION
51              
52             version 0.2.2
53              
54             =head1 SYNOPSIS
55              
56             See the tests.
57              
58             =head1 DESCRIPTION
59              
60             This inherits from L<Test::Data::Split::Backend::Hash> .
61              
62             =head1 METHODS
63              
64             =head2 $pkg->populate([$id1,$data1,$id2,$data2,$id3,$data3...]);
65              
66             Populate the hash with the IDs and data passed as an even lengthed
67             array reference. The IDs must be unique and the
68             L<validate_and_transform> method must be implemented.
69              
70             The accepts an C<< {id => $id, data => $data} >> hash reference and either
71             throws an exception or returns the transformed/mutated data (which can be the
72             same as the original.
73              
74             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
75              
76             =head1 SUPPORT
77              
78             =head2 Websites
79              
80             The following websites have more information about this module, and may be of help to you. As always,
81             in addition to those websites please use your favorite search engine to discover more resources.
82              
83             =over 4
84              
85             =item *
86              
87             MetaCPAN
88              
89             A modern, open-source CPAN search engine, useful to view POD in HTML format.
90              
91             L<https://metacpan.org/release/Test-Data-Split>
92              
93             =item *
94              
95             RT: CPAN's Bug Tracker
96              
97             The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
98              
99             L<https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Data-Split>
100              
101             =item *
102              
103             CPANTS
104              
105             The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
106              
107             L<http://cpants.cpanauthors.org/dist/Test-Data-Split>
108              
109             =item *
110              
111             CPAN Testers
112              
113             The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
114              
115             L<http://www.cpantesters.org/distro/T/Test-Data-Split>
116              
117             =item *
118              
119             CPAN Testers Matrix
120              
121             The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
122              
123             L<http://matrix.cpantesters.org/?dist=Test-Data-Split>
124              
125             =item *
126              
127             CPAN Testers Dependencies
128              
129             The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
130              
131             L<http://deps.cpantesters.org/?module=Test::Data::Split>
132              
133             =back
134              
135             =head2 Bugs / Feature Requests
136              
137             Please report any bugs or feature requests by email to C<bug-test-data-split at rt.cpan.org>, or through
138             the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=Test-Data-Split>. You will be automatically notified of any
139             progress on the request by the system.
140              
141             =head2 Source Code
142              
143             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
144             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
145             from your repository :)
146              
147             L<https://github.com/shlomif/perl-Test-Data-Split>
148              
149             git clone git://github.com/shlomif/perl-Test-Data-Split.git
150              
151             =head1 AUTHOR
152              
153             Shlomi Fish <shlomif@cpan.org>
154              
155             =head1 BUGS
156              
157             Please report any bugs or feature requests on the bugtracker website
158             L<https://github.com/shlomif/perl-Test-Data-Split/issues>
159              
160             When submitting a bug or request, please include a test-file or a
161             patch to an existing test-file that illustrates the bug or desired
162             feature.
163              
164             =head1 COPYRIGHT AND LICENSE
165              
166             This software is Copyright (c) 2014 by Shlomi Fish.
167              
168             This is free software, licensed under:
169              
170             The MIT (X11) License
171              
172             =cut