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

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 96 CC 9 SCAR 26.5
CC
9
Cov
0%
_add_template_path
30.0
_add_form_path
20.0
add_paths
6.0
CRAP 14.2
1 package OpusVL::AppKit::RolesFor::Plugin;
2  
3 use Moose::Role;
4 use Carp;
5 use File::ShareDir qw/module_dir/;
6 use Try::Tiny;
7 use experimental 'smartmatch';
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 my $self = shift;
15 my $module = shift;
16  
17 carp "Please change the module $module to use add_paths instead of add_form_path.";
18 my $module_dir = module_dir($module);
19 $self->_add_form_path($module_dir);
20 }
21  
22 sub add_paths
23 {
24 my $self = shift;
25 my $module = shift;
26  
27 # FIXME: should I do a rel2abs here?
28 my $module_dir = try
29 {
30 module_dir($module);
31 };
32 if($module_dir)
33 {
34 $self->_add_form_path($module_dir);
35 $self->_add_static_path($module_dir);
36 $self->_add_template_path($module_dir);
37 }
38 }
39  
40 sub _add_form_path
41 {
42 my $self = shift;
43 my $module_dir = shift;
44  
45 $self->config->{'Controller::HTML::FormFu'} = { constructor => { config_file_path => [] }} if !$self->config->{'Controller::HTML::FormFu'};
46 $self->config->{'Controller::HTML::FormFu'}->{constructor} = { config_file_path => [] } if !$self->config->{'Controller::HTML::FormFu'}->{constructor};
47 $self->config->{'Controller::HTML::FormFu'}->{constructor}->{config_file_path} = [] if !$self->config->{'Controller::HTML::FormFu'}->{constructor}->{config_file_path};
48 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 my $self = shift;
56 my $module_dir = shift;
57  
58 my $tt_view = $self->config->{default_view} || 'TT';
59 my $template_path = $module_dir . '/root/templates';
60  
61 if($self->view('Excel'))
62 {
63 unless ($self->view('Excel')->{etp_config}->{INCLUDE_PATH} ~~ $template_path) {
64 push @{$self->view('Excel')->{etp_config}->{INCLUDE_PATH}}, $template_path;
65 }
66 $self->view('Excel')->{etp_config}->{AUTO_FILTER} = 'html';
67 $self->view('Excel')->{etp_engine} = 'TTAutoFilter';
68 unless ($self->view($tt_view)->include_path ~~ $template_path) {
69 push @{$self->view($tt_view)->include_path}, $template_path;
70 }
71 }
72 else
73 {
74 my $excel_config = $self->config->{'View::Excel'};
75 unless ($excel_config->{etp_config}->{INCLUDE_PATH} ~~ $template_path) {
76 push @{$excel_config->{etp_config}->{INCLUDE_PATH}}, $template_path;
77 }
78 $excel_config->{etp_config}->{AUTO_FILTER} = 'html';
79 $excel_config->{etp_engine} = 'TTAutoFilter';
80 my $inc_path = $self->config->{'View::AppKitTT'}->{'INCLUDE_PATH'};
81 push(@$inc_path, $template_path );
82 }
83  
84 }
85  
86 sub _add_static_path
87 {
88 my $self = shift;
89 my $module_dir = shift;
90  
91 # .. add static dir into the config for Static::Simple..
92 my $static_dirs = $self->config->{'Plugin::Static::Simple'}->{include_path};
93 unshift(@$static_dirs, File::Spec->rel2abs($module_dir . '/root' ));
94 $self->config->{'Plugin::Static::Simple'}->{include_path} = $static_dirs;
95 }
96  
97 1;
98  
99 __END__