Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by radiantmatrix (Parson)
on Mar 15, 2007 at 20:24 UTC ( [id://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 } );
       $entry->commit;
    }
    
  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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found