Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Extending LValuable Subs with Tied Variables

by Juerd (Abbot)
on Jun 24, 2004 at 22:54 UTC ( [id://369511]=note: print w/replies, xml ) Need Help??


in reply to Extending LValuable Subs with Tied Variables

If pre and post are always executed directly after eachother, then what's the use of separating them? What part of the story am I missing here?

use Attribute::Property; package Cool; sub new : New; sub name : Property { $_ = reverse uc; 1 } package main; my $obj = Cool->new; $obj->name = "My right foot"; print $obj->name, "\n";

[Attribute::Property] doesn't actually provide hooks for pre/post "processing"

It provides a single hook for processing and validation: the code block. The value returned by it determines whether the new value is correct (hence the 1 in the example above), but both $_ and $_[1] are aliases for the value that is about to be set, so there's more than enough chance to manipulate the value before it gets assigned.

It should be noted that I also have no idea what C# does. I tried googling, but found only one sort-of relevant document, which has no examples and no explanation that I immediately grokked.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: Extending LValuable Subs with Tied Variables
by Limbic~Region (Chancellor) on Jun 24, 2004 at 23:43 UTC
    Juerd,
    I was hoping you might reply.

    If pre and post are always executed directly after eachother, then what's the use of separating them?

    I just threw them in there as I wasn't given a real clear definition of how/when they were supposed to be invoked. I assume they would be separate but only perldeveloper can answer that

    It provides a single hook for processing and validation: the code block. The value returned by it determines whether the new value is correct (hence the 1 in the example above), but both $_ and $_1 are aliases for the value that is about to be set, so there's more than enough chance to manipulate the value before it gets assigned.
    There is a lot of history from the CB that this post did not capture. After posting it, I did mention in the CB that Attribute::Property might provide aliases in the validation allowing modification if necessary. It is my fault for not looking at the source and not updating my original post accordingly.

    Cheers - L~R

      I was hoping you might reply.

      How could I not reply? :)

      It is my fault for not looking at the source and not updating my original post accordingly.

      It's documented even. Although it should have been made clearer that the value can also be modified. Currently, only the s/// in the SYNOPSIS really shows that feature.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found