CatalystX::CRUD::ModelAdapter - make CRUD Controllers work with non-CRUD models


CatalystX-CRUD documentation  | view source Contained in the CatalystX-CRUD distribution.

Index


NAME

Top

CatalystX::CRUD::ModelAdapter - make CRUD Controllers work with non-CRUD models

SYNOPSIS

Top

 package My::ModelAdapter::Foo;
 use base qw( CatalystX::CRUD::ModelAdapter );

 # must implement the following methods
 sub new_object { }
 sub fetch      { }
 sub search     { }
 sub iterator   { }
 sub count      { }
 sub make_query { }
 sub search_related     { }
 sub iterator_related   { }
 sub count_related      { }

 1;

 # then in your CX::CRUD::Controller subclass
 package MyApp::Controller::CRUD;
 use base qw( CatalystX::CRUD::Controller );

 __PACKAGE__->config(
    'model_adapter' => 'My::ModelAdapter::Foo'
 );

 1;

DESCRIPTION

Top

CatalystX::CRUD::ModelAdapter allows you to use existing, non-CRUD Models with the CatalystX::CRUD::Controller API. The ModelAdapter class implements a similar API to the CX::CRUD::Model, but does not inherit from Catalyst::Model and should not sit in the ::Model namespace.

If a 'model_adapter' config value is present in a CX::CRUD::Controller subclass, the ModelAdapter instance will be called instead of the 'model_name' instance. The model_name accessor is available on the ModelAdapter instance and is set automatically at instantiation time by the calling Controller.

This documentation is intended for ModelAdapter developers.

CONFIGURATION

Top

You may configure your CXCM-derived Models in the usual way (see the Catalyst Manual).

METHODS

Top

CatalystX::CRUD::ModelAdapter inherits from CatalystX::CRUD.

The following methods should be implemented in your subclass.

new_object( controller, context )

Should return a new instance from the Model you are adapting.

fetch( controller, context, args )

Should return an instance of the Model you are adapting, based on args.

search( controller, context, args )

Should return an arrayref of instances of the Model you are adapting, based on args.

iterator( controller, context, args )

Should return an iterator of instances of the Model you are adapting, based on args.

count( controller, context, args )

Should return an integer representing the numbef of matching instances of the Model you are adapting, based on args.

make_query( controller, context )

Should return appropriate values for passing to search(), iterator() and count(). See CataystX::CRUD::Model for examples.

has_relationship( controller, context, obj, rel_name )

Should return true or false as to whether rel_name exists for obj.

It is up to the subclass to implement this method.

CRUD Methods

Top

The following methods are implemented in CatalystX::CRUD::Object when using the CatalystX::CRUD::Model API. When using the ModelAdapter API, they should be implemented in the adapter class.

create( context, object )

Should implement the C in CRUD.

read( context, object )

Should implement the R in CRUD.

update( context, object )

Should implement the U in CRUD.

delete( context, object )

Should implement the D in CRUD.

AUTHOR

Top

Peter Karman, <perl at peknet.com>

BUGS

Top

Please report any bugs or feature requests to bug-catalystx-crud at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc CatalystX::CRUD

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/CatalystX-CRUD

* CPAN Ratings

http://cpanratings.perl.org/d/CatalystX-CRUD

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD

* Search CPAN

http://search.cpan.org/dist/CatalystX-CRUD

COPYRIGHT & LICENSE

Top


CatalystX-CRUD documentation  | view source Contained in the CatalystX-CRUD distribution.