Peter Karman > CatalystX-CRUD > CatalystX::CRUD::ModelAdapter

Download:
CatalystX-CRUD-0.56.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

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

SYNOPSIS ^

 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 ^

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 ^

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

METHODS ^

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.

search_related( controller, context, obj, relationship )

Returns zero or more CXCO instances like search(). The instances are related to obj via relationship.

iterator_related( controller, context, obj, relationship )

Like search_related() but returns an iterator.

count_related( controller, context, obj, relationship )

Like search_related() but returns an integer.

add_related( controller, context, obj, rel_name, foreign_value )

Associate foreign object identified by foreign_value with obj via the relationship rel_name.

It is up to the subclass to implement this method.

rm_related( controller, context, obj, rel_name, foreign_value )

Dissociate foreign object identified by foreign_value from obj via the relationship rel_name.

It is up to the subclass to implement this method.

put_related( obj, rel_name, foreign_value )

Create new related foreign object. Unlike add_related(), the foreign object need not already exist. put_related() should be idempotent.

find_related( obj, rel_name, foreign_value )

Return related object for foreign_value based on rel_name for obj.

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 ^

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 ^

Peter Karman, <perl at peknet.com>

BUGS ^

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 ^

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

    perldoc CatalystX::CRUD

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2008 Peter Karman, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: