blib/lib/OpusVL/AppKit/RolesFor/Plugin.pm

filter: Statementstmt 25.8% 16 / 62 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 45.4% 5 / 11 Podpod 100% 2 / 2 totaltotal 24.4% 23 / 94 CC 10 SCAR 28.8
CC
10
Cov
20%
_add_template_path
42.0
_add_form_path
20.0
add_paths
6.0
CRAP 17.8
« lib/OpusVL/AppKit/Controller/AppKit/Admin/Users.pm ↑ Summary lib/OpusVL/AppKit/Controller/AppKit/Admin/Access.pm »
1 package OpusVL::AppKit::RolesFor::Plugin;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::ShareDir qw/module_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use experimental 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # this method is provided for compatibility reassons
10 # you should switch to using add_paths instead since it does this
11 # and sets up all the other paths too.
12 sub add_form_path
13 {
14 0 ▶ my $self = shift;
Subroutine add_form_path: not called CC=1 SCAR=6.9
Pod documented
15 0 my $module = shift;
16  
17 0 carp "Please change the module $module to use add_paths instead of add_form_path.";
18 0 my $module_dir = module_dir($module);
19 0 $self->_add_form_path($module_dir);
20 }
21  
22 sub add_paths
23 {
24 0 ▶ my $self = shift;
Subroutine add_paths: not called CC=2 SCAR=17.9
Pod documented
25 0 my $module = shift;
26  
27 # FIXME: should I do a rel2abs here?
28 my $module_dir = try
29 {
30 0 ▶ module_dir($module);
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 };
32 0 ▶ if($module_dir)
Branch: 1 branch
BranchTrueFalseTotal
if ($module_dir) 0 0 0
33 {
34 0 $self->_add_form_path($module_dir);
35 0 $self->_add_static_path($module_dir);
36 0 $self->_add_template_path($module_dir);
37 }
38 }
39  
40 sub _add_form_path
41 {
42 0 ▶ my $self = shift;
Subroutine _add_form_path: not called CC=4 SCAR=30.0
43 0 my $module_dir = shift;
44  
45 0 ▶ $self->config->{'Controller::HTML::FormFu'} = { constructor => { config_file_path => [] }} if !$self->config->{'Controller::HTML::FormFu'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config->{"Controller::HTML::FormFu"} 0 0 0
46 0 ▶ $self->config->{'Controller::HTML::FormFu'}->{constructor} = { config_file_path => [] } if !$self->config->{'Controller::HTML::FormFu'}->{constructor};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config->{"Controller::HTML::FormFu"}{"constructor"} 0 0 0
47 0 ▶ $self->config->{'Controller::HTML::FormFu'}->{constructor}->{config_file_path} = [] if !$self->config->{'Controller::HTML::FormFu'}->{constructor}->{config_file_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config->{"Controller::HTML::FormFu"}{"constructor"}{"config_file_path"} 0 0 0
48 0 push @{$self->config->{'Controller::HTML::FormFu'}->{constructor}->{config_file_path}},
49 $module_dir . '/root/forms';
50 # FIXME: by this point the various controller may be built.
51 }
52  
53 sub _add_template_path
54 {
55 0 ▶ my $self = shift;
Subroutine _add_template_path: not called CC=6 SCAR=37.4
56 0 my $module_dir = shift;
57  
58 0 ▶ my $tt_view = $self->config->{default_view} || 'TT';
Condition0%0/2
$self->config->{'default_view'} || 'TT'
l!l
00
MC/DC0%0/1
$self->config->{'default_view'} || 'TT'
$self->config->{'default_view'}
Truth table0%0/2
A
A= $self->config->{'default_view'}
Aresult
11
00
59 0 my $template_path = $module_dir . '/root/templates';
60  
61 0 ▶ if($self->view('Excel'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->view('Excel')) { } 0 0 0
62 {
63 0 ▶ unless ($self->view('Excel')->{etp_config}->{INCLUDE_PATH} ~~ $template_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->view("Excel")->{"etp_config"}{"INCLUDE_PATH"} ~~ $template_path) 0 0 0
64 0 push @{$self->view('Excel')->{etp_config}->{INCLUDE_PATH}}, $template_path;
65 }
66 0 $self->view('Excel')->{etp_config}->{AUTO_FILTER} = 'html';
67 0 $self->view('Excel')->{etp_engine} = 'TTAutoFilter';
68 0 ▶ unless ($self->view($tt_view)->include_path ~~ $template_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->view($tt_view)->include_path ~~ $template_path) 0 0 0
69 0 push @{$self->view($tt_view)->include_path}, $template_path;
70 }
71 }
72 else
73 {
74 0 my $excel_config = $self->config->{'View::Excel'};
75 0 ▶ unless ($excel_config->{etp_config}->{INCLUDE_PATH} ~~ $template_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($excel_config->{"etp_config"}{"INCLUDE_PATH"} ~~ $template_path) 0 0 0
76 0 push @{$excel_config->{etp_config}->{INCLUDE_PATH}}, $template_path;
77 }
78 0 $excel_config->{etp_config}->{AUTO_FILTER} = 'html';
79 0 $excel_config->{etp_engine} = 'TTAutoFilter';
80 0 my $inc_path = $self->config->{'View::AppKitTT'}->{'INCLUDE_PATH'};
81 0 push(@$inc_path, $template_path );
82 }
83  
84 }
85  
86 sub _add_static_path
87 {
88 0 ▶ my $self = shift;
Subroutine _add_static_path: not called CC=1 SCAR=6.9
89 0 my $module_dir = shift;
90  
91 # .. add static dir into the config for Static::Simple..
92 0 my $static_dirs = $self->config->{'Plugin::Static::Simple'}->{include_path};
93 0 unshift(@$static_dirs, File::Spec->rel2abs($module_dir . '/root' ));
94 0 $self->config->{'Plugin::Static::Simple'}->{include_path} = $static_dirs;
95 }
96  
97 1 1;
98  
99 __END__
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =head1 NAME
106  
107 OpusVL::AppKit::RolesFor::Plugin
108  
109 =head1 VERSION
110  
111 version 2.24
112  
113 =head1 SYNOPSIS
114  
115 with 'OpusVL::AppKit::RolesFor::Plugin';
116  
117  
118 after 'setup_components' => sub {
119 my $class = shift;
120  
121 $class->add_paths(__PACKAGE__);
122  
123 =head1 DESCRIPTION
124  
125 This role helps integrate your module into a catalyst app by adding to the paths setup so that the
126 auto directory contents are included in your app. This includes, TT templates, HTML::FormFu forms,
127 static content and Excel::Template::Plus templates.
128  
129 =head1 NAME
130  
131 OpusVL::AppKit::RolesFor::Plugin
132  
133 =head1 METHODS
134  
135 =head2 add_paths
136  
137 This sets up the paths for the TT templates and the L<Excel::Template::Plus> view. Both views
138 are setup to point to the same directory, named C<templates>. It also sets up the static content path
139 to point to the static directory.
140  
141 It sets up the HTML::FormFu include directory so that it will pick up your forms. The AppKitForm attribute
142 also has some logic to pull forms from the current module but that doesn't allow you to do includes on other forms,
143 either within your own module, or across modules.
144  
145 =head2 add_form_path
146  
147 This sets up the HTML::FormFu include directory so that it will pick up your forms. The AppKitForm attribute
148 also has some logic to pull forms from the current module but that doesn't allow you to do includes on other forms,
149 either within your own module, or across modules.
150  
151 This is called by the add_paths method. The primary reason this method is exposed is that this was originaly
152 the only method on this role. Now I've added the add_paths method you should change any existing modules calling
153 this method to use the add_paths call instead.
154  
155 =head1 AUTHOR
156  
157 OpusVL - www.opusvl.com
158  
159 =head1 COPYRIGHT AND LICENSE
160  
161 This software is copyright (c) 2010 by OpusVL - www.opusvl.com.
162  
163 This is free software; you can redistribute it and/or modify it under
164 the same terms as the Perl 5 programming language system itself.
165  
166 =cut
« lib/OpusVL/AppKit/Controller/AppKit/Admin/Users.pm ↑ Summary lib/OpusVL/AppKit/Controller/AppKit/Admin/Access.pm »