[Dbix-class] RFC: DBICx::Shortcuts

Pedro Melo melo at simplicidade.org
Wed Jan 20 10:26:16 GMT 2010


Hi,


2010/1/20 Андрей Костенко <andrey at kostenko.name>:
> What do you do if collision happens?
> e.g:
> $schema->resultset('Storage')

thats not a collision, I'm not adding the shortcuts to the schema
class but to another class, a shortcuts class. So if your Schema class
is MyApp::Schema, you can create another class, MyApp::S, where your
shortcuts will be created.

So unless you added the storage() method to the shortcut class there
is no collision.

Oh, and the code detects and croaks on collisions. You should then
either rename your method or use the source_info() shortcut key on
your source.

Bye,

>
> On Mon, Jan 18, 2010 at 8:02 PM, Pedro Melo <melo at simplicidade.org> wrote:
>> Hi,
>>
>> I've cleaned up and uploaded to CPAN a small module that I use a lot in my code.
>>
>> I got tired of writting
>>
>> $schema->resultset('Source')->....
>>
>> all the time, and I wrote DBICx::Shortcuts.
>>
>> You create a new class (I usually give it a very small name, like
>> MyApp::S, tweak MyApp to taste), as a subclass of DBICx::Shortcuts and
>> link it to a Schema class with a setup('MyApp::Schema') call.
>>
>> For each source, it creates a shortcut method in your class. So I can write:
>>
>> MyApp::S->source->...
>>
>> As a bonus, you can also call
>>
>> MyApp::S->source($id)
>>
>> as a shortcut to
>>
>> $schema->resultset('Source')->find($id)
>>
>> All other calls to the source() shortcut with parameters will end up
>> as calls to search().
>>
>> Comments, suggestions?
>>
>> Bye,
>> --
>> Pedro Melo
>> http://www.simplicidade.org/
>> xmpp:melo at simplicidade.org
>> mailto:melo at simplicidade.org
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- 
Pedro Melo
http://www.simplicidade.org/
xmpp:melo at simplicidade.org
mailto:melo at simplicidade.org



More information about the DBIx-Class mailing list