Hm ... my first idea was to serialize the blessing package, than I realized that in most cases packages are already serialized - in a text representation - in the representing module.pm ...

Of course you could complain that subs could have been added dynamically outside the module.

So one could think about dumping the STASH ...

DB<26> sub BLA::foo { print "BLA::foo"} DB<27> use Data::Dumper DB<28> p Dumper \%BLA:: $VAR1 = { 'foo' => *BLA::foo, 'AUTOLOAD' => *BLA::AUTOLOAD };

... alas, Data::Dumper won't serialize the sub's body.

Other serializers allow B::Deparse to hook in ( Data::Dump probably, IIRC? ) , but this source representation is not 100% reliable.

And that's where - in my humble opinion - your interesting idea hits a wall.

As long as one can't reliably serialize the code of the subs of a class, one will need to resort to add the class' code manually.°

While it's possible to introspect in which file and line a sub was defined, this will only help if it was static source and not a dynamically built eval $SOURCE .

In short: Serializing the methods of a class is very hard in Perl if it has to be fail proof.

(I was too eager to meditate and too lazy to search, you may want check if CPAN already offers a solution for that :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) On a side note: JS has a method .toSource() for such introspection, which unfortunately lacks in Perl.

update

Anyway ... I'd be interested to know the use case you see. Packages are after all _global_, so resurrecting them might lead to so heavy side effects, that manual interference is needed anyway.


In reply to Re: Class / package weak association by LanX
in thread Class / package weak association by dd-b

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.