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.17';
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.17
13              
14             =cut
15              
16 4     4   28216 use 5.006;
  4         8  
17 4     4   2586 use XML::Simple;
  4         25542  
  4         21  
18 4     4   2329 use Data::Dumper;
  4         27120  
  4         264  
19 4     4   1367 use File::Share ':all';
  4         21784  
  4         531  
20 4     4   1505 use Food::ECodes::Additive;
  4         11  
  4         114  
21              
22 4     4   25 use Moo;
  4         4  
  4         18  
23 4     4   732 use namespace::clean;
  4         7  
  4         19  
24              
25             has 'additives' => (is => 'ro');
26              
27             sub BUILDARGS {
28 2     2 0 1523 my ($class, $args) = @_;
29              
30 2 100       13 die "ERROR: No parameters required for constructor." if defined $args;
31              
32 1         5 my $xml = dist_file('Food-ECodes', 'ecodes.xml');
33 1         248 my $ecode = XMLin($xml, ForceArray => 1, KeyAttr => [ 'ecode' ]);
34 1         942807 my $additives = {};
35              
36 1         2 foreach my $_ecode (@{$ecode->{ecode}}) {
  1         4  
37 473         13892 $additives->{uc($_ecode->{id})} = Food::ECodes::Additive->new($_ecode);
38             }
39              
40 1         379 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 845 my ($self, $code) = @_;
67              
68 2 100       19 die "ERROR: Missing parameter 'ecode'." unless defined $code;
69 1 50       33 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