| 1 | package CatalystX::CMS::Action; | ||||||||||||||||||||||||||||||||||
| 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::Action'; | ||||||||||||||||||||||||||||||||
|
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 CatalystX::CMS; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.011'; | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 2 | my $DEBUG = 0; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 2 | __PACKAGE__->mk_accessors(qw( cms )); | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | #use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||
| 18 | #use Data::Dump::Streamer; | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | CatalystX::CMS::Action - action base class | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | package MyApp::Controller::Foo; | ||||||||||||||||||||||||||||||||||
| 27 | use base ( | ||||||||||||||||||||||||||||||||||
| 28 | 'CatalystX::CMS::Controller', # MUST come first | ||||||||||||||||||||||||||||||||||
| 29 | 'Other::Controller::Base::Class' | ||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | sub bar : Local { | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 1; | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | # if /foo/bar?cxcms=1 then can edit foo/bar.tt | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | CatalystX::CMS::Action isa Catalyst::Action class that handles | ||||||||||||||||||||||||||||||||||
| 43 | all the template management. It is typically accessed | ||||||||||||||||||||||||||||||||||
| 44 | via a subclass of CatalystX::CMS::Controller. | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | Only new or overridden method are documented here. | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | =head2 new([ cms => CatalystX::CMS->new ]) | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | Overrides new() method to call next::method() and then | ||||||||||||||||||||||||||||||||||
| 55 | instantiate a CatalystX::CMS object. | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | You can pass in a B<cms> key/value pair. The value | ||||||||||||||||||||||||||||||||||
| 58 | should be an object that conforms to the CatalystX::CMS | ||||||||||||||||||||||||||||||||||
| 59 | API. | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 64 | 16 | my $self = shift->next::method(@_); | |||||||||||||||||||||||||||||||||
| 65 | 16 | ▶ | $self->{cms} ||= CatalystX::CMS->new( $self->class->config->{cms} ); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"cms"} ||= "CatalystX::CMS"->new($self->class->config->{"cms"})
MC/DC0%0/2
$self->{"cms"} ||= "CatalystX::CMS"->new($self->class->config->{"cms"})
$self->{"cms"}
"CatalystX::CMS"->new($self->class->config->{"cms"})
Truth table33%1/3
A ||= B
A= $self->{"cms"}B= "CatalystX::CMS"->new($self->class->config->{"cms"})
| |||||||||||||||||||||||||||||||||||
| 66 | 16 | return $self; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | =head2 execute( I<args> ) | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | Checks for the presence the C<cxcms> request parameter. | ||||||||||||||||||||||||||||||||||
| 72 | If present and true, calls the cms() method instead of the | ||||||||||||||||||||||||||||||||||
| 73 | action's target method. | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 18 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 78 | 18 | my ( $self, $controller, $c, @arg ) = @_; | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | #Dump( $self->{code} )->To( \*STDERR )->Out(); | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 18 | ▶ | if ( !$c->stash->{cms_mode} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $c->stash->{"cms_mode"} and exists $c->req->params->{"cxcms"}
MC/DC100%2/2
not $c->stash->{"cms_mode"} and exists $c->req->params->{"cxcms"}
not $c->stash->{"cms_mode"}
exists $c->req->params->{"cxcms"}
Truth table100%3/3
not(A) and B
A= not $c->stash->{"cms_mode"}B= exists $c->req->params->{"cxcms"}
| |||||||||||||||||||||||||||||||||||
| 83 | and exists $c->req->params->{cxcms} ) | ||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||
| 85 | 3 | $c->stash( cms_mode => $c->req->params->{cxcms} ); | |||||||||||||||||||||||||||||||||
| 86 | 3 | $self->do_cms( $controller, $c, | |||||||||||||||||||||||||||||||||
| 87 | $controller->cms_template_for( $c, @arg ) ); | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 3 | $c->forward('_END'); | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||||||||
| 92 | 15 | return $self->next::method( $controller, $c, @arg ); | |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | #sub match { | ||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||
| 99 | # #carp 'match: ' . dump \@_; | ||||||||||||||||||||||||||||||||||
| 100 | # my $self = shift; | ||||||||||||||||||||||||||||||||||
| 101 | # my $ret = $self->next::method(@_); | ||||||||||||||||||||||||||||||||||
| 102 | # return $ret; | ||||||||||||||||||||||||||||||||||
| 103 | #} | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | =head2 do_cms( I<controller>, I<c>, I<arg> ) | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | The primary engine of the CMS. Called via execute() if the | ||||||||||||||||||||||||||||||||||
| 108 | C<cxcms> param is true. | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | Possible values for the C<cxcms> parameter: | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | =over | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | =item | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | create | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | =item | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | edit | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | =item | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | cancel | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | =item | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | save | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | =item | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | preview | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | =item | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | diff | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | =item | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | history | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | =item | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | blame | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | =back | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | See the documentation for CatalystX::CMS for the method name matching | ||||||||||||||||||||||||||||||||||
| 149 | the C<cxcms> value. | ||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 3 | ▶ | sub do_cms { | ||||||||||||||||||||||||||||||||
|
Subroutine
do_cms: called CC=14 SCAR=34.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 154 | 3 | my ( $self, $controller, $c, $page ) = @_; | |||||||||||||||||||||||||||||||||
| 155 | 3 | ▶ | unless ( $controller->cms_may_edit($c) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | $c->error('permission denied'); | |||||||||||||||||||||||||||||||||
| 157 | 0 | return; | |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | $page ||= $controller->cms_template_for( $c, $c->action ); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$page ||= $controller->cms_template_for($c, $c->action)
MC/DC0%0/2
$page ||= $controller->cms_template_for($c, $c->action)
$page
$controller->cms_template_for($c, $c->action)
Truth table33%1/3
A ||= B
A= $pageB= $controller->cms_template_for($c, $c->action)
| |||||||||||||||||||||||||||||||||||
| 161 | 3 | my $method = $self->get_http_method($c); | |||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | $c->log->debug("$method -> $page") if $c->debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | 3 | my $res = $self->cms->$method( $c, $controller, $page ); | |||||||||||||||||||||||||||||||||
| 164 | 3 | ▶ | $c->log->debug( "cms $method returned " . dump $res ) if $c->debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 3 | ▶ | $DEBUG and warn "cms $method returned " . dump($res); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | # set current_view in case we have many | ||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | $c->stash->{current_view} ||= $self->cms->view_name; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c->stash->{"current_view"} ||= $self->cms->view_name
MC/DC0%0/2
$c->stash->{"current_view"} ||= $self->cms->view_name
$c->stash->{"current_view"}
$self->cms->view_name
Truth table33%1/3
A ||= B
A= $c->stash->{"current_view"}B= $self->cms->view_name
| |||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | # set base url for this page since it requires $controller | ||||||||||||||||||||||||||||||||||
| 172 | 3 | ▶ | $c->stash->{cmspage_url} ||= $c->uri_for( $page->url ); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c->stash->{"cmspage_url"} ||= $c->uri_for($page->url)
MC/DC0%0/2
$c->stash->{"cmspage_url"} ||= $c->uri_for($page->url)
$c->stash->{"cmspage_url"}
$c->uri_for($page->url)
Truth table33%1/3
A ||= B
A= $c->stash->{"cmspage_url"}B= $c->uri_for($page->url)
| |||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | if ( !defined $res ) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 175 | $c->stash( | ||||||||||||||||||||||||||||||||||
| 176 | cms_mode => 'edit', | ||||||||||||||||||||||||||||||||||
| 177 | cmspage => $page, | ||||||||||||||||||||||||||||||||||
| 178 | template => 'cms/yui/editor.tt', | ||||||||||||||||||||||||||||||||||
| 179 | 0 | error => join( "\n", @{ $c->error } ), | |||||||||||||||||||||||||||||||||
| 180 | ); | ||||||||||||||||||||||||||||||||||
| 181 | 0 | $c->clear_errors; | |||||||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||
| 184 | elsif ( $res->{uri} ) { | ||||||||||||||||||||||||||||||||||
| 185 | 2 | $c->res->redirect( $res->{uri} ); | |||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | if ( $c->can('flash') and exists $res->{message} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->can("flash") and exists $res->{"message"}
MC/DC0%0/2
$c->can("flash") and exists $res->{"message"}
$c->can("flash")
exists $res->{"message"}
Truth table33%1/3
A and B
A= $c->can("flash")B= exists $res->{"message"}
| |||||||||||||||||||||||||||||||||||
| 187 | 0 | $c->flash( message => $res->{message} ); | |||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | elsif ( $res->{body} ) { | ||||||||||||||||||||||||||||||||||
| 191 | 1 | $c->res->body( $res->{body} ); | |||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | $c->res->status( $res->{status} || 200 ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->{'status'} || 200
MC/DC0%0/1
$res->{'status'} || 200
$res->{'status'}
Truth table50%1/2
A
A= $res->{'status'}
| |||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||
| 195 | 0 | $c->stash( %$res, cmspage => $page ); | |||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 3 | return 1; | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | =head2 get_http_method | ||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | Works just like the http_method in CatalystX::CRUD::REST. Returns | ||||||||||||||||||||||||||||||||||
| 204 | the request method, deferring to the C<x-tunneled-method> or | ||||||||||||||||||||||||||||||||||
| 205 | C<_http_method> params if present. | ||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 3 | ▶ | sub get_http_method { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_http_method: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 210 | 3 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 211 | return | ||||||||||||||||||||||||||||||||||
| 212 | uc( $c->req->params->{'x-tunneled-method'} | ||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | || $c->req->params->{'_http_method'} | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$c->req->params->{'x-tunneled-method'} || $c->req->params->{'_http_method'} || $c->req->method
$c->req->params->{"x-tunneled-method"} or $c->req->params->{"_http_method"}
MC/DC0%0/3
$c->req->params->{'x-tunneled-method'} || $c->req->params->{'_http_method'} || $c->req->method
$c->req->params->{"x-tunneled-method"}
$c->req->params->{"_http_method"}
$c->req->method
Truth table50%2/4
A or B || C
A= $c->req->params->{"x-tunneled-method"}B= $c->req->params->{"_http_method"}C= $c->req->method
| |||||||||||||||||||||||||||||||||||
| 214 | || $c->req->method ); | ||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | __END__ | ||||||||||||||||||||||||||||||||||