perlquestion
matija
<p>Oh glorious and incredibly patient fellow monks, can anybody please enlighten me how to add a method to a ResultSet class in DBIx::Class?</P>
Here is what I'm trying to do:
<code>
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:12
# 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;
</code>
<p>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 <code>$schema->resultset('Article')->insert_article(...)</code>
</p>
<p>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.
<p>I did read [id://658193], 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.</p>
<p>I'd be grateful for any pointers...</p>