File Coverage

blib/lib/Food/ECodes.pm
Criterion Covered Total %
statement 32 33 96.9
branch 5 6 83.3
condition n/a
subroutine 9 9 100.0
pod 1 2 50.0
total 47 50 94.0


line stmt bran cond sub pod time code
1             package Food::ECodes;
2              
3             $Food::ECodes::VERSION = '0.18';
4             $Food::ECodes::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Food::ECodes - Interface to Food Additive ECodes.
9              
10             =head1 VERSION
11              
12             Version 0.18
13              
14             =cut
15              
16 2     2   137019 use 5.006;
  2         14  
17 2     2   1621 use XML::Simple;
  2         16687  
  2         91  
18 2     2   1315 use Data::Dumper;
  2         12283  
  2         105  
19 2     2   733 use File::Share ':all';
  2         47498  
  2         287  
20 2     2   926 use Food::ECodes::Additive;
  2         6  
  2         63  
21              
22 2     2   17 use Moo;
  2         4  
  2         9  
23 2     2   745 use namespace::clean;
  2         4  
  2         22  
24              
25             has 'additives' => (is => 'ro');
26              
27             sub BUILDARGS {
28 2     2 0 1821 my ($class, $args) = @_;
29              
30 2 100       63 die "ERROR: No parameters required for constructor." if defined $args;
31              
32 1         6 my $xml = dist_file('Food-ECodes', 'ecodes.xml');
33 1         316 my $ecode = XMLin($xml, ForceArray => 1, KeyAttr => [ 'ecode' ]);
34 1         1390102 my $additives = {};
35              
36 1         3 foreach my $_ecode (@{$ecode->{ecode}}) {
  1         4  
37 473         17735 $additives->{uc($_ecode->{id})} = Food::ECodes::Additive->new($_ecode);
38             }
39              
40 1         276 return { additives => $additives };
41             };
42              
43             =head1 DESCRIPTION
44              
45             It provides simple interface to the Ecodes library.
46              
47             =head1 SYNOPSIS
48              
49             use strict; use warnings;
50             use Food::ECodes;
51              
52             my $ecode = Food::ECodes->new;
53             my $additive = $ecode->search('E100');
54             print "Name: ", $additive->name, "\n";
55              
56             =head1 METHODS
57              
58             =head2 search()
59              
60             Returns object of type L on success, which can be then
61             further queried.
62              
63             =cut
64              
65             sub search {
66 2     2 1 765 my ($self, $code) = @_;
67              
68 2 100       39 die "ERROR: Missing parameter 'ecode'." unless defined $code;
69 1 50       12 die "ERROR: Invalid ecode '$code' received." unless (exists $self->{additives}->{uc($code)});
70              
71 0           return $self->{additives}->{$code};
72             }
73              
74             =head1 AUTHOR
75              
76             Mohammad S Anwar, C<< >>
77              
78             =head1 REPOSITORY
79              
80             L
81              
82             =head1 BUGS
83              
84             Please report any bugs or feature requests to C
85             or through the web interface at L.
86             I will be notified, and then you'll automatically be notified of progress on your
87             bug as I make changes.
88              
89             =head1 SUPPORT
90              
91             You can find documentation for this module with the perldoc command.
92              
93             perldoc Food::ECodes
94              
95             You can also look for information at:
96              
97             =over 4
98              
99             =item * RT: CPAN's request tracker
100              
101             L
102              
103             =item * AnnoCPAN: Annotated CPAN documentation
104              
105             L
106              
107             =item * CPAN Ratings
108              
109             L
110              
111             =item * Search CPAN
112              
113             L
114              
115             =back
116              
117             =head1 LICENSE AND COPYRIGHT
118              
119             Copyright (C) 2011 - 2016 Mohammad S Anwar.
120              
121             This program is free software; you can redistribute it and/or modify it under
122             the terms of the the Artistic License (2.0). You may obtain a copy of the full
123             license at:
124              
125             L
126              
127             Any use, modification, and distribution of the Standard or Modified Versions is
128             governed by this Artistic License.By using, modifying or distributing the Package,
129             you accept this license. Do not use, modify, or distribute the Package, if you do
130             not accept this license.
131              
132             If your Modified Version has been derived from a Modified Version made by someone
133             other than you,you are nevertheless required to ensure that your Modified Version
134             complies with the requirements of this license.
135              
136             This license does not grant you the right to use any trademark, service mark,
137             tradename, or logo of the Copyright Holder.
138              
139             This license includes the non-exclusive, worldwide, free-of-charge patent license
140             to make, have made, use, offer to sell, sell, import and otherwise transfer the
141             Package with respect to any patent claims licensable by the Copyright Holder that
142             are necessarily infringed by the Package. If you institute patent litigation
143             (including a cross-claim or counterclaim) against any party alleging that the
144             Package constitutes direct or contributory patent infringement,then this Artistic
145             License to you shall terminate on the date that such litigation is filed.
146              
147             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
148             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
149             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
150             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
151             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
152             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
153             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154              
155             =cut
156              
157             1; # End of Food::ECodes