Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Perl attributes are typically handled at CHECK time - between compile time (BEGIN) and INIT time, and way before run time. Your eval happens at run time, so too late to effect attribute processing.

It is in fact possible to alter when processing happens for particular attributes, but it needs to be one of the compilation phases (BEGIN, CHECK, INIT or END), and not runtime.

* * *

As it happens I've been working on some aspect-oriented programming stuff for Moose that might be just what you need.

{ package User; use Moose; has name => (is => 'ro', isa => 'Str'); sub login { my $self = shift; print $self->name, " is logged in\n"; } } { package Tracing; use MooseX::Aspect; my $aspect = __PACKAGE__; sub log_msg { my $class = shift; print STDERR "TRACE: $_\n" for @_; } apply_to 'User' => role { before login => sub { my $self = shift; $aspect->log_msg($self->name . " attempted to log in"); }; }; } # try setting tracing to 0 :-) my $config = { tracing => 1 }; if ($config->{tracing}) { Tracing->setup; } my $bob = User->new( name => 'Bob' ); $bob->login;

Packages of interest: Moose, MooseX::Aspect, Sub::Talisman and MooseX::ModifyTaggedMethods.

MooseX::Aspect is still at a very early stage of development, and bugs abound. But I think it shows quite a bit of promise for doing this sort of thing.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Core module: Attribute::Handlers behaviour by tobyink
in thread Core module: Attribute::Handlers behaviour by enigma

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2016-10-27 23:07 GMT
    Find Nodes?
      Voting Booth?
      How many different varieties (color, size, etc) of socks do you have in your sock drawer?

      Results (372 votes). Check out past polls.