MenuGrinder.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 41 CC 2 SCAR 11.0
CC
2
Cov
0%
ACCEPT_CONTEXT
6.0
BEGIN
2.0
_build__menu
2.0
CRAP 3.0
1 package Catalyst::Model::MenuGrinder;
2 BEGIN {
3 $Catalyst::Model::MenuGrinder::VERSION = '0.07';
4 }
5  
6 # ABSTRACT: Catalyst Model base class for WWW::MenuGrinder
7 # This looks a lot like Catalyst::Model::Factory::PerRequest, but it differs
8 # in that it constructs the MenuGrinder object once on startup, loading all of
9 # the plugins and such, and then delegates to the glue's "accept_context" on
10 # ACCEPT_CONTEXT. We could probably remove a layer here and switch to PerRequest
11 # but that's for later.
12  
13 use Moose;
14 extends 'Catalyst::Model';
15  
16 use Scope::Guard;
17 use Module::Runtime;
18  
19 has '_menu' => (
20 is => 'rw',
21 builder => '_build__menu',
22 lazy => 1,
23 );
24  
25 has 'menu_class' => (
26 is => 'ro',
27 isa => 'Str',
28 default => 'Catalyst::Model::MenuGrinder::Menu',
29 );
30  
31 has 'menu_config' => (
32 is => 'ro',
33 isa => 'HashRef',
34 default => sub { +{} },
35 );
36  
37 sub _build__menu {
38 my ($self) = @_;
39  
40 return Module::Runtime::use_module($self->menu_class)->new(
41 config => $self->menu_config,
42 );
43 }
44  
45 sub ACCEPT_CONTEXT {
46 my ($self, $c) = @_;
47  
48 $c->stash->{__menu_guard} = [] unless defined $c->stash->{__menu_guard};
49 push @{ $c->stash->{__menu_guard} }, Scope::Guard->new(sub {
50 $self->_menu->cleanup();
51 }
52 );
53  
54 $self->_menu->_accept_context($c);
55  
56 return $self->_menu;
57 }
58  
59 sub BUILD {
60 my ($self) = @_;
61  
62 # Force loading at startup
63 $self->_menu;
64 }
65  
66 1;
67  
68  
69 __END__