CatalystX::CMS::Controller - controller base class


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

Index


Code Index:

NAME

Top

CatalystX::CMS::Controller - controller 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=edit then can edit foo/bar.tt

DESCRIPTION

Top

CatalystX::CMS::Controller is a Catalyst::Controller base class for use with CatalystX::CMS.

METHODS

Top

Only new or overridden method are documented here.

new

Merges config with app config and then calls next::method().

create_action( args )

Overrides base method to use set default Action class as CatalystX::CMS::Action instead of Catalyst::Action.

cms_template_for( c, args )

Returns a CatalystX::CMS::Page object to be acted upon. The default assumes the same logic as Catalyst::View::TT but you may override to implement different naming scheme or logic.

args is an array. args is what is passed to the CatalystX::CMS::Action execute() method. See Catalyst::Action execute() documentation for details.

If present, args will be joined with a / and passed to the CMS model.

If no args are present, then $c->action->reverse is used.

If the special request param cxcms-url is present in $c->req->params, then that value will override all others and will be used as the file argument to the CMS model.

cms_may_edit( c )

Default returns true. Override to implement authorization.

cms_list

Default local URL method for browsing the pages available in the CMS. Uses the cms/svn/list.tt template by default.

Override this method in your local controller to customize the browsing of your CMS.

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::Controller;
use strict;
use warnings;
use base 'Catalyst::Controller';
use Carp;
use Data::Dump qw( dump );
use MRO::Compat;
use mro 'c3';
use Catalyst::Utils;

our $VERSION = '0.010';

__PACKAGE__->mk_accessors(qw( cms ));

# default config
__PACKAGE__->config(
    cms => {
        model_name             => 'CMS',
        view_name              => 'CMS',
        actionclass_per_action => 0,
        use_editor             => 1,
        use_layout             => 1,
        editor                 => {
            height => '300',
            width  => '550',
        },
        default_type    => 'html',
        default_flavour => 'default',
        lock_period     => 3600,
    }
);

sub new {

    my ( $class, $app ) = @_;

    my $class_conf = $class->config->{cms};
    my $app_conf   = $app->config->{cms};
    unless ( exists $class_conf->{root} ) {
        my $rroot = $app_conf->{root}->{r}
            || [
            ( $app_conf->config->{root} || $app_conf->path_to('root') ) ];
        my $rwroot = $app_conf->{root}->{rw}
            || [ $app_conf->path_to('../cms') ];

        $class_conf->{root}->{r}  ||= $rroot;
        $class_conf->{root}->{rw} ||= $rwroot;
    }

    $class->config(
        cms => $class->merge_config_hashes( $app_conf, $class_conf ) );

    return shift->next::method(@_);
}

sub create_action {
    my $self = shift;

    return $self->next::method(@_) if $self->cms->{actionclass_per_action};

    my %args = @_;

    my $class = (
        exists $args{attributes}{ActionClass}
        ? $args{attributes}{ActionClass}[0]
        : 'CatalystX::CMS::Action'
    );

    unless ( Class::Inspector->loaded($class) ) {
        require Class::Inspector->filename($class);
    }

    return $class->new( \%args );
}

sub cms_template_for {
    my ( $self, $c, @arg ) = @_;
    my $file;
    if ( exists $c->req->params->{'cxcms-url'} ) {
        $file = $c->req->params->{'cxcms-url'};
    }
    else {
        $file = @arg ? join( '/', @arg ) : $c->action->reverse;
    }
    return $c->model( $self->cms->{model_name} )->fetch( file => $file );
}

sub cms_may_edit {1}

sub cms_list : Local {
    my ( $self, $c ) = @_;
    my $pages = $c->model( $self->cms->{model_name} )->search();
    $c->stash( pages    => $pages );
    $c->stash( template => 'cms/svn/list.tt' );
    $c->stash( new_file => 1 );    # hide the 'Edit this page' link
}

1;

__END__