MenuGrinder/Plugin/XMLLoader.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 40 CC 2 SCAR 11.5
CC
2
Cov
0%
BUILD
6.0
BEGIN
2.0
load
2.0
CRAP 3.1
1 package WWW::MenuGrinder::Plugin::XMLLoader;
2 BEGIN {
3 $WWW::MenuGrinder::Plugin::XMLLoader::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: WWW::MenuGrinder plugin that loads menus with XML::Simple.
7  
8 use Moose;
9  
10 use XML::Simple;
11  
12 with 'WWW::MenuGrinder::Role::Loader';
13  
14 has 'filename' => (
15 is => 'rw',
16 );
17  
18 sub load {
19 my ($self) = @_;
20  
21 # XML::Simple screws up UTF-8 somehow...
22 open my $menufh, '<:encoding(UTF-8)', $self->filename or die $!;
23 my $menu_xml = do { local $/; <$menufh> };
24  
25 my $menu = XMLin($menu_xml, ForceArray => [ qw(item) ]);
26  
27 return $menu;
28 }
29  
30 sub BUILD {
31 my ($self) = @_;
32  
33 my $filename = $self->grinder->config->{filename};
34 die "config->{filename} is required" unless defined $filename;
35  
36 $self->filename($filename);
37 }
38  
39 __PACKAGE__->meta->make_immutable;
40  
41 no Moose;
42  
43 1;
44  
45  
46 __END__