On 30/10/2007, Jonathan Rockway <[EMAIL PROTECTED]> wrote:
> Jonas Alves wrote:
> > Hi,
> >
> > I want my dbic components to be able to extend the ResultSet by adding
> > base classes when they are loaded.
>
> How about:
>
>    package MyApp::ResultSet::FooAndBar
>    use base qw/MyApp::ResultSet::Foo MyApp::ResultSet::Bar/;
>    1;
>
> If you want something more dynamic:
>
>    package MyApp::RS::Base;
>    use Moose;
>    extends 'DBIx::Class::ResultSet';
>    1;
>
>    package MyApp::RS::Role::Foo;
>    use Moose::Role;
>    sub foo { }
>    1;
>
>    <same idea for bar>
>
> Then you can say:
>
>    __PACKAGE__->resultset_class('MyApp::RS::Base');
>    __PACKAGE__->resultset_class->meta->apply_role('MyApp::RS::Role::Foo');
>
> Have I tested any of this?  No.  YMMV.
>
> (Dynamically building classes at runtime is probably a Bad Idea anyway.
> I suggest just going with the inheritance method shown first; just
> create a separate RS class for each case where you need one.)
>
> Regards,
> Jonathan Rockway
>

Hi Jonathan,
I really like your Moose approach, but i would like  a solution that
just require the user to load_component my  extensions and with that
get the ResultSet methods for free.
What I  ended up doing was add this two methods to my extensions:

sub table {
    my ($self,@rest) = @_;
    my $ret = $self->next::method(@rest);
    $self->_register_rs_class if @rest;
    return $ret;
}

sub _register_rs_class {
    my $self = shift;
    my $source = eval { $self->result_source_instance }
       || $self->result_source;
    $source->resultset_class->load_components('+MyDBIC::ResultSet::Foo');
}

Thanks anyway,
-- 
Jonas

_______________________________________________
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