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...


In reply to Add a method to a ResultSet Class in DBIx::Class? by matija

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.