Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader


Maypole documentation Contained in the Maypole distribution.

Index


Code Index:

NAME

Top

Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader

SYNOPSIS

Top

    package Foo;
    use 'Maypole::Application';

    Foo->config->model("Maypole::Model::CDBI::Plain");
    Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]);

    # untaint columns and provide custom actions for each class

    Foo::SomeTable->untaint_columns(email => ['email'], printable => [qw/name description/]);

    Foo::Other::Table->untaint_columns ( ... );

    sub Foo::SomeTable::SomeAction : Exported {

        . . .

    }

DESCRIPTION

Top

This module allows you to use Maypole with previously set-up Class::DBI classes; simply call setup with a list reference of the classes you're going to use, and Maypole will work out the tables and set up the inheritance relationships as normal.

METHODS

Top

Action Methods

Top

Action methods are methods that are accessed through web (or other public) interface.

Inherited from Maypole::Model::CDBI::Base

do_edit

If there is an object in $r->objects, then it should be edited with the parameters in $r->params; otherwise, a new object should be created with those parameters, and put back into $r->objects. The template should be changed to view, or edit if there were any errors. A hash of errors will be passed to the template.

do_delete

Inherited from Maypole::Model::CDBI::Base.

This action deletes records

Inherited from Maypole::Model::CDBI::Base.

This action method searches for database records.

list

Inherited from Maypole::Model::CDBI::Base.

The list method fills $r->objects with all of the objects in the class. The results are paged using a pager.

Helper Methods

Top

Untainter

Set the class you use to untaint and validate form data Note it must be of type CGI::Untaint::Maypole (takes $r arg) or CGI::Untaint

setup

  This method is inherited from Maypole::Model::Base and calls setup_database,
  which uses Class::DBI::Loader to create and load Class::DBI classes from
  the given database schema.

setup_database

  This method loads the model classes for the application

class_of

  returns class for given table

adopt

This class method is passed the name of a model class that represensts a table and allows the master model class to do any set-up required.

SEE ALSO

Top

Maypole::Model::Base

Maypole::Model::CDBI


Maypole documentation Contained in the Maypole distribution.
package Maypole::Model::CDBI::Plain;
use strict;

use Maypole::Config;
use base 'Maypole::Model::CDBI::Base';

use Maypole::Model::CDBI::AsForm;
use Maypole::Model::CDBI::FromCGI;
use CGI::Untaint::Maypole;

sub Untainter { 'CGI::Untaint::Maypole' };

sub setup_database {
    my ( $self, $config, $namespace, $classes ) = @_;
    $config->{classes}        = $classes;
    foreach my $class (@$classes) { $namespace->load_model_subclass($class); }
    $namespace->model_classes_loaded(1);
    $config->{table_to_class} = { map { $_->table => $_ } @$classes };
    $config->{tables}         = [ keys %{ $config->{table_to_class} } ];
}

sub class_of {
    my ( $self, $r, $table ) = @_;
    return $r->config->{table_to_class}->{$table};
}

sub adopt {
    my ( $self, $child ) = @_;
    if ( my $col = $child->stringify_column ) {
        $child->columns( Stringify => $col );
    }
}


1;