Dear monks,

I'm in a bit of a conundrum. I'm writing a manager for user created objects (think CMS or file manager) which are stored in folders (related to a "folder" table in the database). If a user doesn't create subfolders, his objects are created in the main folder. There is no real main folder for each user; his objects are just stored with folder id 0.

I now have some methods that need to be called on a folder, e.g. a method that lists the objects in a folder. I handled the main folder by creating a DBIx::Class::Row object in-memory with new(), but can't seem to be able to call the object's methods, or access the relationship accessors which DBIx::Class usually creates automatically. DBIx::Class only seems to connect relationships if the object has been loaded from storage (or created in-storage).

Is it possible to connect the relationships to the in-memory object somehow? Remember that this object does not exist as a row in the database, but the relationships would still be valid (because of the column value 0 for the folder id). I only need the relationships one-way.

Alternatively, is it possible to assign methods to this object (package instance) without modifying the package? I can fake the one or two relationships I need with simple subs, but I can't attach those to the instance.

If it is not possible, I will have to create main folders for each user, move the objects to these folders and update a number of Controller actions that deal with folders. Your help would be very appreciated.


In reply to Adding a new method to a package instance / Connecting DBIx::Class relationships to in-memory objects by Cybris

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.