IMHO you are doing the right thing, but i can advice you a futher
improvement and very important - perfomance boost for your module.

You can do shorcuts shorter:
     in setup_finalize of Catalyst:

        foreach my $source ($schema->sources) {
            next unless index($source, '::') == -1;
            my $acc = "${source}RS";
            $c->mk_group_accessors(inherited => $acc) unless $c->can($acc);
            $c->$acc( scalar $schema->resultset($source) );
        }

You gain very short accesors (which cannon conflict due to 'RS' suffix)
for example
   $c->UserRS->single(...)
   $c->ChatMessageRS->search(...)

Plus - such accessors works MUCH MUCH faster than $schema->resultset because
->resultset method generates new empty resultset every time and this
operation is quite hard for DBIC (why???!!!).
With this accessors all empty resultsets has been already generated on start.

2010/1/18 Pedro Melo <[email protected]>:
> 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:[email protected]
> mailto:[email protected]
>
> _______________________________________________
> 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/[email protected]
>

_______________________________________________
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/[email protected]

Reply via email to