[Catalyst] Doing work inside the DBIx::Class model

Peter Sørensen maspsr at sdu.dk
Thu Feb 21 08:17:33 GMT 2008


>He meant result_source:
>http://cpan.uwinnipeg.ca/htdocs/DBIx-Class/DBIx/Class/ResultSet.html#result_source
>
>But this is not all and it is something that begs for a FAQ entry - I always forget how to do it.  The important thing is how to add new >>>methods to the ResultSet:
>
>package ArchivedBooks;
>  use base qw/DBIx::Class/;
>  __PACKAGE__->table('books_archive');
>  __PACKAGE__->source_name('Books');
>  __PACKAGE__->resultset_class('ArchivedBooks::ResultSet');
>
>package ArchivedBooks::ResultSet;
>use strict;
>use warnings;
>
>use base qw( DBIx::Class::ResultSet );
>
>sub advanced_search {
> my ( $self, $params, $attrs ) = @_;
>
>$self now is a ResultSet - so you can use methods on it.
......................


I have a similar problem want -  to add some custom methods to the model. I've read
your references but still - I can't get this thing to work.

I have generated the model using Catalyst and get the following layout:

      LogParser.pm
      LogParser
      |
      |________Components.pm
      |________Connectinfo.pm
      |________Logtype.pm

and if I take a look into Components it looks like:

package LogParser::Schema::LogParserDB::Components;

use strict;
use warnings;

use base 'DBIx::Class';

__PACKAGE__->load_components("Core");
__PACKAGE__->table("components");
__PACKAGE__->add_columns(
  "id",
  { data_type => "INT", default_value => undef, is_nullable => 0, size => 11 },
  "component",
  { data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 32 },
  "regex",
  { data_type => "TEXT", default_value => "", is_nullable => 0, size => 65535 },
  "nvars",
  { data_type => "INT", default_value => 1, is_nullable => 0, size => 10 },
  "varnames",
  { data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 64 },
);
__PACKAGE__->set_primary_key("id");


# Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-02-12 17:08:38
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gkSc31rRGpYHxL8tAAd/kw

# You can replace this text with custom content, and it will be preserved on regeneration
1;

As I understand I have to add to above:

__PACKAGE__->source_name('SomeName');
__PACKAGE__->resultset_class('Components::ResultSet');
LogParser::Schema::LogParserDB::Components;ame" 
and create a new package with:

package LogParser::Schema::LogParserDB::Components::ResultSet;
use strict;
use warnings;

use base qw( DBIx::Class::ResultSet );

sub advanced_search {
 my ( $self, $params, $attrs ) = @_;
}
1;

So I created Components/ResultSet.pm  with this content.

But it fails with :

Couldn't instantiate component "LogParser::Model::LogParserDB", "Cannot load schema class 'LogParser::Schema::LogParserDB': Can't locate object method "source_name" via package "LogParser::Schema::LogParserDB::Components::ResultSet" at /usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Schema.pm line 301.

I tried to remove the line:
__PACKAGE__->source_name('SomeName');

but still same problem.

As I read the docs the meaning of this is to use another name than the
default name so why use it???

Regards

Peter Sorensen/University of Southern Denmark/mail: maspsr at sdu.dk



More information about the Catalyst mailing list