in reply to Re: RFC: Simulating Python's @decorators in Perl with Attributes
in thread RFC: Simulating Python's @decorators in Perl with Attributes
so this code might be explicit but repeats the subname hello as a string.
around 'hello' => \&makebold;
Please note that attributes are not necessarily wrapping code.
One use-case for instance could be to set a breakpoint for the debugger
sub tst :break { ... }
Another to restrict the type to variables
my $y :Int;
which might be very helpful when trying to translate Perl code to a typed language like C.
All use cases could be achieved by adding tst or $y to a hash somewhere, but the possibility to do it right at the point of interest w/o name repetition can be very handy and avoids headaches when refactoring.
Just imagine the overhead for a refactoring tool to find all hellos after sub hello was renamed.
Cheers Rolf
( addicted to the Perl Programming Language)
I'm no expert of Moose's compile phases, but a DRY notation of around using attributes would look like
sub hello :around(makebold) { return "ohai"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RFC: Simulating Python's @decorators in Perl with Attributes
by pokki (Monk) on May 28, 2013 at 19:54 UTC | |
by LanX (Saint) on May 28, 2013 at 20:20 UTC |