Your example is quite unclear to me. What is this supposed to to?

sub mylol { my $self=shift; { local $self; $self->{data} = {newdata => 1}; $lol = super(); } }

You could simply localize ->{data} and be on your merry way:

sub mylol { my $self = shift; local $self->{data} = { newdata => 1 }; super(); # $self->{data} is restored here };

(or, depending on what super() does, just ditch whatever contraptions Moose creates, and directly call $self->SUPPER::mylol, to achieve your goal).

Update: After having looked at Moose::super, I'm not really sure what your aversion is against package variables, as it uses them as well. And your locally setting $self is quite unlikely to have any sane (or desired) effect as likely the referenced global variables in Moose:: get set from a wrapper installed by Moose::override:

package Moose; ... our $SUPER_PACKAGE; our $SUPER_BODY; our @SUPER_ARGS; sub super { # This check avoids a recursion loop - see # t/bugs/super_recursion.t return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller(); return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS); }

I'm not sure what that contraption is supposed to achieve, but then, maybe that's because I have either never encountered the problems that Moose attempts to solve or have always taken other approaches to these problems.


In reply to Re: creating an altered clone of a Moose object for a limited scope by Corion
in thread creating an altered clone of a Moose object for a limited scope by metaperl

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.