http://qs321.pair.com?node_id=661319

matija has asked for the wisdom of the Perl Monks concerning the following question:

Oh glorious and incredibly patient fellow monks, can anybody please enlighten me how to add a method to a ResultSet class in DBIx::Class?

Here is what I'm trying to do:
package ThreadedDB::Article; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("article"); __PACKAGE__->add_columns( "id", { data_type => "INT", default_value => undef, is_nullable => 0, size + => 11 }, # etc, etc, etc ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( "article_texts", "ThreadedDB::ArticleText", { "foreign.article" => "self.id" }, ); # Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-01-03 18:12:1 +2 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Y0WFrRSlgOqaz/fbhRt98A #package ThreadedDB::Article::ResultSet; #use base 'DBIx::Class::ResultSet'; sub insert_article { my ($self, $topic, $parent, $msgtext) = @_; my $articles = $self->resultset('Article'); eval { $self->txn_do (sub { # a complex operation that is not relevant yet }) }; } 1;

In other words, I'd like to find a way to put a method into the Article.pm file in such a way that I could access it by doing $schema->resultset('Article')->insert_article(...)

I've tried directly declaring the class (as commented out, above) but it didn't work. Either I'm misunderstanding what the resulting class should be called, or I'm misunderstanding something else.

I did read Re^2: [DBIX::Class] problem with Arbitrary SQL through a custom ResultSource, but it didn't help since the method I need contains a bunch of code (not all of which can be in SQL), and all of which should be done inside a transaction.

I'd be grateful for any pointers...