in reply to Re: Is tie inteded to be used in this way?
in thread Is tie inteded to be used in this way?

No need for string eval:
for (qw(STORE CLEAR PUSH POP SHIFT UNSHIFT)) { my $s = "SUPER::$_"; no strict 'refs'; *$_ = sub { &main::trigger; shift()->$s(@_) }; }

Update: fixed error (removed the reference from \@_).

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: Is tie inteded to be used in this way?
by Eily (Monsignor) on Apr 28, 2015 at 14:49 UTC

    Here's what I did when trying to use closures (I hadn't seen the issue with the double $self at the time):

    { no strict; for my $method (qw(STORE CLEAR PUSH POP SHIFT UNSHIFT)) { my $sub = "SUPER::$method"; *$method = sub { &main::trigger; my $self = shift; $self->$sub($se +lf, @_) }; } }
    So I felt that with all the lexicals and the use of many "advanced" features (anonymous sub, closing over a lexical, globs, scalar as a method, SUPER::) it was harder to read than a string eval which is often better understood. Your version is light enough that I like it more though.

    It's up to Discipulus to choose whatever he thinks he'll be able to understand the best :)

Re^3: Is tie inteded to be used in this way?
by Discipulus (Canon) on Apr 28, 2015 at 20:20 UTC
    very nice, thanks choroba
    anyway i like string eval for his extreme power: the compiler walk with you during the program execution. is just a matter of not abuse as i do sometimes.
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Hmm, eval is a beautiful function. I have used it to do slightly or even very geeky things. But in real production code, well, I have used it to check if I could open a file (when not being able to open it was not necessarily an error) or if a date was valid, when an invalid date was not sufficient to mandate an exception. (This happens, sometimes!). Not more.
      Je suis Charlie.