Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

RFR: Inside-out classes - a Class::InsideOut primer

by radiantmatrix (Parson)
on Mar 15, 2007 at 20:24 UTC ( #605062=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    # Accessing an attribute inside a traditional object
    $self->{ attribute } = $value;
    # Accessing an attribute inside an inside-out object
    $attribute { id $self } = $value;
  2. or download this
    package My::Person;
       $ssn{ id $self } = shift;
       $position{ id $self } = shift;
  3. or download this
    use My::Person;
    print "Old phone is: ",$manager->phone();
    $manager->phone('555-1313'); #set new phone number
    print "New phone is: ",$manager->phone();
  4. or download this
    $manager->{phone} = '555-1313';
  5. or download this
    protection accessor_name => my %attribute_variable;
  6. or download this
    # $obj->public_attrib() accessor, $obj->public_attrib($value) mutator
    public   public_attrib => my %public_attrib;
    # no accessor or mutator
    private  priv_attrib   => my %priv_attrib;
  7. or download this
    sub sendPhoneToDirectory {
       # sends the phone number to the company directory, using SSN as
       $entry->phone( $phone{ id $self } );
  8. or download this
    sub _set_birthday {
       # remember, $_ will contain the value passed to the mutator
       die "$_ is not a valid date" unless m{(\d{2})/(\d{2})/(\d{4})};
       $_ = mktime(0,0,0,$2-1,$1-1,$3-1900); #pack it!
  9. or download this
    public   birthday => my %birthday, { set_hook => \&_set_birthday };
  10. or download this
    sub _get_birthday {
       # remember, $_ will contain the value of the attribute
       strftime '%m/%d/%Y', localtime( $_ );
  11. or download this
    public   birthday => my %birthday, {
       set_hook => \&_set_birthday,  # was already here
       get_hook => \&_get_birthday,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://605062]
Approved by liverpole
[Corion]: Maybe the Perl you try stand-alone and the Perl you run are different?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-06-23 12:16 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.