MenuGrinder/Plugin/SimpleLoader.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 43 CC 2 SCAR 11.0
CC
2
Cov
0%
BUILD
6.0
BEGIN
2.0
load
2.0
CRAP 3.0
1 package WWW::MenuGrinder::Plugin::SimpleLoader;
2 BEGIN {
3 $WWW::MenuGrinder::Plugin::SimpleLoader::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: WWW::MenuGrinder plugin that loads menus with XML::Simple.
7  
8 use Moose;
9 use Parse::RecDescent;
10 use File::Slurp qw(read_file);
11  
12 with 'WWW::MenuGrinder::Role::Loader';
13  
14 has 'filename' => (
15 is => 'rw',
16 );
17  
18 has 'parser' => (
19 is => 'ro',
20 default => sub {
21 my $grammar = do { local $/; <DATA> };
22 return Parse::RecDescent->new($grammar);
23 },
24 );
25  
26  
27 sub load {
28 my ($self) = @_;
29 my $parser = $self->parser;
30 my $menu_text = read_file($self->filename);
31 my $menu = $parser->menu(\$menu_text);
32  
33 return $menu;
34 }
35  
36 sub BUILD {
37 my ($self) = @_;
38  
39 my $filename = $self->grinder->config->{filename};
40 die "config->{filename} is required" unless defined $filename;
41  
42 $self->filename($filename);
43 }
44  
45 __PACKAGE__->meta->make_immutable;
46  
47 no Moose;
48  
49 1;
50  
51  
52  
53  
54 =pod
55  
56 =head1 NAME
57  
58 WWW::MenuGrinder::Plugin::SimpleLoader - WWW::MenuGrinder plugin that loads menus with XML::Simple.
59  
60 =head1 VERSION
61  
62 version 0.06
63  
64 =head1 DESCRIPTION
65  
66 C<WWW::MenuGrinder::Plugin::SimpleLoader> is a plugin for C<WWW::MenuGrinder>.
67 You should not use it directly, but include it in the C<plugins> section of a
68 C<WWW::MenuGrinder> config.
69  
70 This is an experimental input plugin that uses a custom
71 L<Parse::RecDescent>-based grammar designed as a lightweight format for menu
72 files and reminiscent of the BIND config format.
73  
74 =head2 Configuration
75  
76 The key C<filename> in the global configuration holds the name of the file to be
77 read.
78  
79 =head1 AUTHOR
80  
81 Andrew Rodland <andrew@hbslabs.com>
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 This software is copyright (c) 2011 by HBS Labs, LLC..
86  
87 This is free software; you can redistribute it and/or modify it under
88 the same terms as the Perl 5 programming language system itself.
89  
90 =cut
91  
92  
93 __DATA__