CatalystX::CMS::Action - action base class


CatalystX-CMS documentation Contained in the CatalystX-CMS distribution.

Index


Code Index:

NAME

Top

CatalystX::CMS::Action - action base class

SYNOPSIS

Top

 package MyApp::Controller::Foo;
 use base (
    'CatalystX::CMS::Controller',    # MUST come first
    'Other::Controller::Base::Class'
 );

 sub bar : Local {

 }

 1;

 # if /foo/bar?cxcms=1 then can edit foo/bar.tt

DESCRIPTION

Top

CatalystX::CMS::Action isa Catalyst::Action class that handles all the template management. It is typically accessed via a subclass of CatalystX::CMS::Controller.

METHODS

Top

Only new or overridden method are documented here.

new([ cms => CatalystX::CMS->new ])

Overrides new() method to call next::method() and then instantiate a CatalystX::CMS object.

You can pass in a cms key/value pair. The value should be an object that conforms to the CatalystX::CMS API.

execute( args )

Checks for the presence the cxcms request parameter. If present and true, calls the cms() method instead of the action's target method.

do_cms( controller, c, arg )

The primary engine of the CMS. Called via execute() if the cxcms param is true.

Possible values for the cxcms parameter:

create

edit

cancel

save

preview

diff

history

blame

See the documentation for CatalystX::CMS for the method name matching the cxcms value.

get_http_method

Works just like the http_method in CatalystX::CRUD::REST. Returns the request method, deferring to the x-tunneled-method or _http_method params if present.

AUTHOR

Top

Peter Karman, <karman@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-catalystx-cms@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Top

The Minnesota Supercomputing Institute http://www.msi.umn.edu/ sponsored the development of this software.

COPYRIGHT & LICENSE

Top


CatalystX-CMS documentation Contained in the CatalystX-CMS distribution.
package CatalystX::CMS::Action;
use strict;
use warnings;
use base 'Catalyst::Action';
use Carp;
use Data::Dump qw( dump );
use MRO::Compat;
use mro 'c3';
use CatalystX::CMS;

our $VERSION = '0.010';

my $DEBUG = 0;

__PACKAGE__->mk_accessors(qw( cms ));

#use Scalar::Util qw( blessed );
#use Data::Dump::Streamer;

sub new {
    my $self = shift->next::method(@_);
    $self->{cms} ||= CatalystX::CMS->new( $self->class->config->{cms} );
    return $self;
}

sub execute {
    my ( $self, $controller, $c, @arg ) = @_;

    #Dump( $self->{code} )->To( \*STDERR )->Out();

    if ( !$c->stash->{cms_mode}
        and exists $c->req->params->{cxcms} )
    {
        $c->stash( cms_mode => $c->req->params->{cxcms} );
        $self->do_cms( $controller, $c,
            $controller->cms_template_for( $c, @arg ) );

        $c->forward('_END');
    }
    else {
        return $self->next::method( $controller, $c, @arg );
    }

}

#sub match {
#
#    #carp 'match: ' . dump \@_;
#    my $self = shift;
#    my $ret  = $self->next::method(@_);
#    return $ret;
#}

sub do_cms {
    my ( $self, $controller, $c, $page ) = @_;
    unless ( $controller->cms_may_edit($c) ) {
        $c->error('permission denied');
        return;
    }

    $page ||= $controller->cms_template_for( $c, $c->action );
    my $method = $self->get_http_method($c);
    $c->log->debug("$method -> $page") if $c->debug;
    my $res = $self->cms->$method( $c, $controller, $page );
    $c->log->debug( "cms $method returned " . dump $res ) if $c->debug;

    $DEBUG and warn "cms $method returned " . dump($res);

    # set current_view in case we have many
    $c->stash->{current_view} ||= $self->cms->view_name;

    # set base url for this page since it requires $controller
    $c->stash->{cmspage_url} ||= $c->uri_for( $page->url );

    if ( !defined $res ) {
        $c->stash(
            cms_mode => 'edit',
            cmspage  => $page,
            template => 'cms/yui/editor.tt',
            error    => join( "\n", @{ $c->error } ),
        );
        $c->clear_errors;
        return;
    }
    elsif ( $res->{uri} ) {
        $c->res->redirect( $res->{uri} );
        if ( $c->can('flash') and exists $res->{message} ) {
            $c->flash( message => $res->{message} );
        }
    }
    elsif ( $res->{body} ) {
        $c->res->body( $res->{body} );
        $c->res->status( $res->{status} || 200 );
    }
    else {
        $c->stash( %$res, cmspage => $page );
    }

    return 1;
}

sub get_http_method {
    my ( $self, $c ) = @_;
    return
        uc(    $c->req->params->{'x-tunneled-method'}
            || $c->req->params->{'_http_method'}
            || $c->req->method );
}

1;

__END__