MenuGrinder/Plugin/XMLLoader.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 36 CC 2 SCAR 12.0
CC
2
Cov
0%
BUILD
6.0
load
2.0
BEGIN
2.0
CRAP 3.3
1 package WWW::MenuGrinder::Plugin::XMLLoader;
2 our $VERSION = '0.01_01';
3  
4  
5 # ABSTRACT: WWW::MenuGrinder plugin that loads menus with XML::Simple.
6  
7 use Moose;
8  
9 use XML::Simple;
10  
11 with 'WWW::MenuGrinder::Role::Loader';
12  
13 has 'filename' => (
14 is => 'rw',
15 );
16  
17 sub load {
18 my ($self) = @_;
19  
20 # XML::Simple screws up UTF-8 somehow...
21 open my $menufh, '<:encoding(UTF-8)', $self->filename or die $!;
22 my $menu_xml = do { local $/; <$menufh> };
23  
24 my $menu = XMLin($menu_xml, ForceArray => [ qw(item) ]);
25  
26 return $menu;
27 }
28  
29 sub BUILD {
30 my ($self) = @_;
31  
32 my $filename = $self->grinder->config->{filename};
33 die "config->{filename} is required" unless defined $filename;
34  
35 $self->filename($filename);
36 }
37  
38 no Moose;
39  
40 1;
41  
42  
43 __END__
44 =head1 NAME
45  
46 WWW::MenuGrinder::Plugin::XMLLoader - WWW::MenuGrinder plugin that loads menus with XML::Simple.
47  
48 =head1 VERSION
49  
50 version 0.01_01
51  
52 =head1 DESCRIPTION
53  
54 C<WWW::MenuGrinder::Plugin::XMLLoader> is a plugin for C<WWW::MenuGrinder>. You
55 should not use it directly, but include it in the C<plugins> section of a
56 C<WWW::MenuGrinder> config.
57  
58 This is an input plugin that uses L<XML::Simple> to load a menu structure.
59  
60 TODO example file.
61  
62 =head2 Configuration
63  
64 The key C<filename> in the global configuration holds the name of the file to be
65 read.
66  
67 =head1 AUTHOR
68  
69 Andrew Rodland <andrew@hbslabs.com>
70  
71 =head1 COPYRIGHT AND LICENSE
72  
73 This software is copyright (c) 2009 by HBS Labs, LLC..
74  
75 This is free software; you can redistribute it and/or modify it under
76 the same terms as perl itself.
77