#!/usr/bin/perl package Agent; use _Initialize; @ISA = qw( _Initialize tools ); sub _init { my ($self, %args) = @_; $self->tools::_init(%args); #$self->PunMeister::_init(%args); $self->{_acolytes} = $args{followers}; $self->{_philosophy} = $args{manifesto}; } sub DESTROY { my ($self) = @_; print "pg dtor\n"; no strict "refs"; foreach my $parent ( @{ref($self)."::ISA"} ) { my $destructor = $parent."::DESTROY"; $self->$destructor(); } } 1;
package _Initialize; use strict; sub new { my ($class, %args) = @_; my $self = bless {}, ref($class)||$class; $self->_init(%args); return $self; } sub DESTROY {} 1;
#!/usr/bin/perl package tools; @ISA = qw( _Initialize ); sub _init { my ($self, %args) = @_; $self->{_name} = $args{name}; $self->{_alias} = $args{moniker}; $self->{_langs} = $args{languages}; } 1;
#!/usr/bin/perl use Data::Dumper; use Agent; my $config = Agent->new(); print Dumper($config);
while trying this i got error :
Can't locate object method "new" via package "Agent" at test.pl line 10.
and if i add use _Initailize to Agent, i get another error :
Can't locate object method "_init" via package "tools" (perhaps you forgot to lo ad "tools"?) at Agent.pm line 10. pg dtor

2006-11-11 Retitled by g0n, as per Monastery guidelines
Original title: 'Inheritance'


In reply to Implementing inheritance in Perl by opensourcer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.