lib/CatalystX/CMS/Controller.pm

filter: Statementstmt 90.0% 54 / 60 Branchbran 66.6% 8 / 12 Conditioncond 30.7% 4 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 92.8% 13 / 14 Podpod n/a totaltotal 73.8% 79 / 107 CC 12 SCAR 14.7
CC
12
Cov
78%
new
10.1
create_action
4.0
cms_template_for
3.2
CRAP 4.3
« lib/CatalystX/CMS/View.pm ↑ Summary lib/CatalystX/CMS/Page.pm »
1 package CatalystX::CMS::Controller;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base 'Catalyst::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Dump qw( dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Catalyst::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.011';
12  
13 2 __PACKAGE__->mk_accessors(qw( cms ));
14  
15 # default config
16 2 __PACKAGE__->config(
17 cms => {
18 model_name => 'CMS',
19 view_name => 'CMS',
20 actionclass_per_action => 0,
21 use_editor => 1,
22 use_layout => 1,
23 editor => {
24 height => '300',
25 width => '550',
26 },
27 default_type => 'html',
28 default_flavour => 'default',
29 lock_period => 3600,
30 }
31 );
32  
33 =head1 NAME
34  
35 CatalystX::CMS::Controller - controller base class
36  
37 =head1 SYNOPSIS
38  
39 package MyApp::Controller::Foo;
40 use base (
41 'CatalystX::CMS::Controller', # MUST come first
42 'Other::Controller::Base::Class'
43 );
44
45 sub bar : Local {
46
47 }
48
49 1;
50
51 # if /foo/bar?cxcms=edit then can edit foo/bar.tt
52
53 =head1 DESCRIPTION
54  
55 CatalystX::CMS::Controller is a Catalyst::Controller
56 base class for use with CatalystX::CMS.
57
58 =head1 METHODS
59  
60 Only new or overridden method are documented here.
61  
62 =cut
63  
64 =head2 new
65  
66 Merges config with app config and then calls next::method().
67  
68 =cut
69  
70 2 ▶sub new {
Subroutine new: called CC=7 SCAR=23.2
71  
72 2 my ( $class, $app ) = @_;
73  
74 2 my $class_conf = $class->config->{cms};
75 2 my $app_conf = $app->config->{cms};
76 2 ▶ unless ( exists $class_conf->{root} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $class_conf->{"root"}) 2 0 2
77 my $rroot = $app_conf->{root}->{r}
78 || [
79 2 ▶ ( $app_conf->config->{root} || $app_conf->path_to('root') ) ];
Condition20%1/5
$app_conf->{'root'}{'r'} || [$app_conf->config->{'root'} || $app_conf->path_to('root')]
l!l
20
$app_conf->config->{'root'} || $app_conf->path_to('root')
l!l&&r!l&&!r
000
MC/DC0%0/1
$app_conf->{'root'}{'r'} || [$app_conf->config->{'root'} || $app_conf->path_to('root')]
$app_conf->{'root'}{'r'}
MC/DC0%0/2
$app_conf->config->{'root'} || $app_conf->path_to('root')
$app_conf->config->{'root'} $app_conf->path_to('root')
Truth table50%1/2
A
A= $app_conf->{'root'}{'r'}
Aresult
11
00
Truth table0%0/3
A || B
A= $app_conf->config->{'root'}B= $app_conf->path_to('root')
ABresult
1X1
011
000
80 my $rwroot = $app_conf->{root}->{rw}
81 2 ▶ || [ $app_conf->path_to('../cms') ];
Condition50%1/2
$app_conf->{'root'}{'rw'} || [$app_conf->path_to('../cms')]
l!l
20
MC/DC0%0/1
$app_conf->{'root'}{'rw'} || [$app_conf->path_to('../cms')]
$app_conf->{'root'}{'rw'}
Truth table50%1/2
A
A= $app_conf->{'root'}{'rw'}
Aresult
11
00
82  
83 2 ▶ $class_conf->{root}->{r} ||= $rroot;
Condition33%1/3
$class_conf->{"root"}{"r"} ||= $rroot
l!l&&r!l&&!r
020
MC/DC0%0/2
$class_conf->{"root"}{"r"} ||= $rroot
$class_conf->{"root"}{"r"} $rroot
Truth table33%1/3
A ||= B
A= $class_conf->{"root"}{"r"}B= $rroot
ABresult
1X1
011
000
84 2 ▶ $class_conf->{root}->{rw} ||= $rwroot;
Condition33%1/3
$class_conf->{"root"}{"rw"} ||= $rwroot
l!l&&r!l&&!r
020
MC/DC0%0/2
$class_conf->{"root"}{"rw"} ||= $rwroot
$class_conf->{"root"}{"rw"} $rwroot
Truth table33%1/3
A ||= B
A= $class_conf->{"root"}{"rw"}B= $rwroot
ABresult
1X1
011
000
85 }
86  
87 $class->config(
88 2 cms => $class->merge_config_hashes( $app_conf, $class_conf ) );
89  
90 2 return shift->next::method(@_);
91 }
92  
93 =head2 create_action( I<args> )
94  
95 Overrides base method to use set default Action
96 class as CatalystX::CMS::Action instead of Catalyst::Action.
97  
98 =cut
99  
100 16 ▶sub create_action {
Subroutine create_action: called CC=4 SCAR=13.9
101 16 my $self = shift;
102  
103 16 ▶ return $self->next::method(@_) if $self->cms->{actionclass_per_action};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cms->{"actionclass_per_action"} 0 16 16
104  
105 16 my %args = @_;
106  
107 my $class = (
108 exists $args{attributes}{ActionClass}
109 16 ▶ ? $args{attributes}{ActionClass}[0]
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'attributes'}{'ActionClass'} ? : 1 15 16
110 : 'CatalystX::CMS::Action'
111 );
112  
113 16 ▶ unless ( Class::Inspector->loaded($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Class::Inspector"->loaded($class)) 2 14 16
114 2 require Class::Inspector->filename($class);
115 }
116  
117 16 return $class->new( \%args );
118 }
119  
120 =head2 cms_template_for( I<c>, I<args> )
121  
122 Returns a CatalystX::CMS::Page object to be acted upon.
123 The default assumes the same logic as Catalyst::View::TT but you
124 may override to implement different naming scheme or logic.
125  
126 I<args> is an array. I<args> is what is passed to the
127 CatalystX::CMS::Action execute()
128 method. See Catalyst::Action execute() documentation for details.
129  
130 If present, I<args> will be joined with a C</> and passed to the CMS model.
131  
132 If no I<args> are present, then $c->action->reverse is used.
133  
134 If the special request param C<cxcms-url> is present in $c->req->params,
135 then that value will override all others and will
136 be used as the C<file> argument to the CMS model.
137  
138 =cut
139  
140 5 ▶sub cms_template_for {
Subroutine cms_template_for: called CC=3 SCAR=11.8
141 5 my ( $self, $c, @arg ) = @_;
142 5 my $file;
143 5 ▶ if ( exists $c->req->params->{'cxcms-url'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $c->req->params->{'cxcms-url'}) { } 0 5 5
144 0 $file = $c->req->params->{'cxcms-url'};
145 }
146 else {
147 5 ▶ $file = @arg ? join( '/', @arg ) : $c->action->reverse;
Branch: 1 branch
BranchTrueFalseTotal
@arg ? : 5 0 5
148 }
149 5 return $c->model( $self->cms->{model_name} )->fetch( file => $file );
150 }
151  
152 =head2 cms_may_edit( I<c> )
153  
154 Default returns true. Override to implement authorization.
155  
156 =cut
157  
158 3 ▶sub cms_may_edit {1}
Subroutine cms_may_edit: called CC=1 SCAR=0.0
159  
160 =head2 cms_list
161  
162 Default local URL method for browsing the pages available in the CMS.
163 Uses the C<cms/svn/list.tt> template by default.
164  
165 Override this method in your local controller to customize
166 the browsing of your CMS.
167  
168 =cut
169  
170 0 ▶sub cms_list : Local {
Subroutine cms_list: not called CC=1 SCAR=6.9
171 0 my ( $self, $c ) = @_;
172 0 my $pages = $c->model( $self->cms->{model_name} )->search();
173 0 $c->stash( pages => $pages );
174 0 $c->stash( template => 'cms/svn/list.tt' );
175 0 $c->stash( new_file => 1 ); # hide the 'Edit this page' link
176 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
177  
178 2 1;
179  
180 __END__
« lib/CatalystX/CMS/View.pm ↑ Summary lib/CatalystX/CMS/Page.pm »