Catalyst::Plugin::CRUD - CRUD (create/read/update/delete) Plugin for Catalyst


Catalyst-Plugin-CRUD documentation Contained in the Catalyst-Plugin-CRUD distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::CRUD - CRUD (create/read/update/delete) Plugin for Catalyst

SYNOPSIS

Top

  package MyApp;

  use Catalyst qw/-Debug ConfigLoader I18N CRUD Static::Simple/;

  1;

  package MyApp::Controller::Foo;

  sub create : Local {
    my ($self, $c) = @_;
    $c->create($self);
  }

  1;

DESCRIPTION

Top

This module provides CRUD (create/read/update/delete) action.

 create: insert new record
 read:   retrieve record
 update: update already record
 delete: delete record
 list:   retrieve all records

EXPORT

None by default.

METHODS

Top

create

Create action. This method internally calls Catalyst::Controller::[CDBI|DBIC]::create.

read

Read action. This method internally calls Catalyst::Controller::[CDBI|DBIC]::read.

update

Update action. This method internally calls Catalyst::Controller::[CDBI|DBIC]::update.

delete

Delete action. This method internally calls Catalyst::Controller::[CDBI|DBIC]::delete.

list

List action This method internally calls Catalyst::Controller::[CDBI|DBIC]::list.

Class::DBI::toHashRef

DBIx::Class::toHashRef

SEE ALSO

Top

Catalyst, Catalyst::Controller::CRUD

AUTHOR

Top

Jun Shimizu, <bayside@cpan.org>

COPYRIGHT AND LICENSE

Top


Catalyst-Plugin-CRUD documentation Contained in the Catalyst-Plugin-CRUD distribution.
package Catalyst::Plugin::CRUD;

use strict;
use warnings;
use Catalyst::Controller::CRUD::CDBI;
use Catalyst::Controller::CRUD::DBIC;
use Scalar::Util qw(blessed);

our $VERSION = '0.21';

sub create {
    my ( $c, $self ) = @_;
    my $type = $self->setting($c)->{type} || 'CDBI';
    my $cntl = "Catalyst::Controller::CRUD::" . $type;
    $cntl->create($c, $self);
}

sub read {
    my ( $c, $self ) = @_;
    my $type = $self->setting($c)->{type} || 'CDBI';
    my $cntl = "Catalyst::Controller::CRUD::" . $type;
    $cntl->read($c, $self);
}

sub update {
    my ( $c, $self ) = @_;
    my $type = $self->setting($c)->{type} || 'CDBI';
    my $cntl = "Catalyst::Controller::CRUD::" . $type;
    $cntl->update($c, $self);
}

sub delete {
    my ( $c, $self ) = @_;
    my $type = $self->setting($c)->{type} || 'CDBI';
    my $cntl = "Catalyst::Controller::CRUD::" . $type;
    $cntl->delete($c, $self);
}

sub list {
    my ( $c, $self ) = @_;
    my $type = $self->setting($c)->{type} || 'CDBI';
    my $cntl = "Catalyst::Controller::CRUD::" . $type;
    $cntl->list($c, $self);
}

sub Class::DBI::toHashRef {
    my ( $self ) = @_;

    my %hash = $self->_as_hash;
    return \%hash;
}

sub DBIx::Class::toHashRef {
    my ( $self ) = @_;

    # see http://search.cpan.org/dist/DBIx-Class-AsFdat
    my $hash;
    for my $column ($self->result_source->columns) {
        $hash->{$column} = $self->$column;

        # inflate the datetime
        if (blessed($hash->{$column}) and $hash->{$column}->isa('DateTime')) {
            for my $type (qw(year month day hour minute second)) {
                $hash->{"${column}_$type"}  = $hash->{$column}->$type;
            }
        }
    }
    return $hash;
}

1;