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