Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl OO with Class::Struct

by dbuckhal (Monk)
on Dec 17, 2013 at 07:43 UTC ( #1067426=note: print w/ replies, xml ) Need Help??


in reply to Perl OO with Class::Struct

Just for fun... And I'm more of a dog fan, too. :)

#!/usr/bin/perl use strict; use warnings; { package Dog; sub new { my ( $caller, $dog ) = @_; my $class = ref($caller) || $caller; my $dogs = { NAME => $dog, }; bless $dogs, $class; } sub name { my $self = shift; ( @_ ) ? $self->{NAME} = shift : return $self->{NAME}; } } { package Litter; sub new { my ( $caller, $list ) = @_; die "not an DOG ref" unless ref($list->[0]) eq "Dog"; my $class = ref($caller) || $caller; my $litter = { DOGS => $list, }; bless $litter, $class; } sub dogs { my $self = shift; ( @_ ) ? $self->{DOGS} = shift : return $self->{DOGS}; } } my $dog1 = Dog->new('Strider'); my $dog2 = Dog->new('Bella'); my $litter = Litter->new([$dog1, $dog2]); for ( @{$litter->dogs} ) { print $_->name . "\n" }


Comment on Re: Perl OO with Class::Struct
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-08-21 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls