Gantry

 view release on metacpan or  search on metacpan

lib/Gantry/Plugins/AutoCRUDHelper/DBIxClass.pm  view on Meta::CPAN

package Gantry::Plugins::AutoCRUDHelper::DBIxClass;
use strict;

sub insert {
    my $class       = shift;
    my $gantry_site = shift;
    my $params      = shift;
    my $schema      = $gantry_site->get_schema();
    my $table_name  = $gantry_site->get_model_name->table_name();

    $schema->txn_begin();
    my $new_row     = $schema->resultset( $table_name )->create( $params );
    $schema->txn_commit();

    return $new_row;
}

sub retrieve {
    my $class       = shift;
    my $gantry_site = shift;
    my $id          = shift;

    my $schema      = $gantry_site->get_schema();
    my $table_name  = $gantry_site->get_model_name->table_name();

    my $retrow      = $schema->resultset( $table_name )->find( $id );

    return $retrow;
}

sub update {
    my $class       = shift;
    my $gantry_site = shift;
    my $row         = shift;
    my $params      = shift;

    my $schema      = $gantry_site->get_schema();

    $schema->txn_begin();
    $row->update( $params );
    $row->discard_changes();
    $schema->txn_commit();
}

sub delete {
    my $class       = shift;
    my $gantry_site = shift;
    my $row         = shift;

    my $schema      = $gantry_site->get_schema();
    $schema->txn_begin();
    $row->delete;
    $schema->txn_commit();
}

1;

=head1 NAME

Gantry::Plugins::AutoCRUDHelper::DBIxClass - the actual CRUD for DBIx::Class AutoCRUD

=head1 SYNOPSIS

This module is required for you by Gantry::Plugins::AutoCRUD, when your
controller's get_orm_helper module returns
'Gantry::Plugins::AutoCRUDHelper::DBIxClass'.  It supports models which
inherit from DBIx::Class.

=head1 DESCRIPTION

Inside Gantry::Plugins::AutoCRUD, whenever actual database work needs to be
done, your model is asked to supply a helper by calling get_orm_helper.
If your models use DBIx::Class, you need to implement that method and have
it return 'Gantry::Plugins::AutoCRUDHelper::DBIxClass'.

=head1 METHODS

The methods of this module are documented in Gantry::Plugins::AutoCRUD,
but here is a list to keep POD testers happy:

=over 4

=item insert

=item retrieve

=item update

=item delete

=back



( run in 1.760 second using v1.01-cache-2.11-cpan-0fb53d1c279 )