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

Re^2: Class::Accessor and Damian's PBP

by nothingmuch (Priest)
on Feb 22, 2006 at 20:59 UTC ( #532091=note: print w/ replies, xml ) Need Help??


in reply to Re: Class::Accessor and Damian's PBP
in thread Class::Accessor and Damian's PBP

Whenever your setter needs to be normalized to a different value lvalue accessors don't cut it.

-nuffin
zz zZ Z Z #!perl


Comment on Re^2: Class::Accessor and Damian's PBP
Re^3: Class::Accessor and Damian's PBP
by Roy Johnson (Monsignor) on Feb 22, 2006 at 21:04 UTC
    Neither do generated accessors. So you have to write something. For either kind of accessor, tie is one way to do it.

    Caution: Contents may have been coded under pressure.
      uh, override the set method?

      -nuffin
      zz zZ Z Z #!perl
        That's exactly equivalent to overriding the STORE method for a tied variable. Advantage: none.

        Caution: Contents may have been coded under pressure.
Re^3: Class::Accessor and Damian's PBP
by TheDamian (Priest) on Feb 25, 2006 at 20:09 UTC
    Whenever your setter needs to be normalized to a different value lvalue accessors don't cut it.
    Well...that certainly used to be the case. Indeed, the fact that you have to employ the complexities of tied proxy variables to retain control when using lvalue accessors, is precisely why I cautioned against lvalue accessors in "Perl Best Practices".

    But last week I released the latest version of the Contextual::Return module, with which you can now hide all the complexity of tied proxies behind two simple LVALUE, and RVALUE blocks. For example:

    use Contextual::Return; # Name method offers unconstrained access... sub name : lvalue { my ($self) = @_; $name_of{ident $self}; } # Rank method constrains access: can assign only valid ranks # (value being assigned is passed as $_ to LVALUE block)... sub rank : lvalue { my ($self) = @_; LVALUE { croak "Invalid rank ($_) assigned" if !$is_valid_rank{$_}; $rank_of{ident $self} = $_; } RVALUE { $rank_of{ident $self}; } } # Serial method offers read-only access... sub serial { my ($self) = @_; return $snum_of{ident $self}; }

    With this functionality now available, I'm seriously reconsidering my long-held objections to lvalue accessors.

    Damian

      Wow, that's pretty nice... Great work =)

      -nuffin
      zz zZ Z Z #!perl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-25 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls