[33034] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4310 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 16 16:09:14 2014

Date: Sun, 16 Nov 2014 13:09:02 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 16 Nov 2014     Volume: 11 Number: 4310

Today's topics:
        steal a class <gravitalsun@hotmail.foo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 16 Nov 2014 22:15:49 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: steal a class
Message-Id: <m4b0lm$7g2$1@news.ntua.gr>

Here is how a class to use an other class and all its properties.
This more powerfull from the   @ISA=qw/other classes/  trick, have fun





#!/usr/bin/perl
use strict;
use warnings;
use feature qw/say/;

my $A = ClassA->new();

$A->methodA();
$A->{ClassB}->methodB;
$A->{ClassB}->{Bp1}='foo';
$A->{ClassB}->methodB;



BEGIN  {
package ClassA;
our @ISA     = ();
our $VERSION = '1.0';

sub new {
my $class = ref shift || __PACKAGE__;
my $self  = { Ap1=>'Av01', Ap2=>'Av01'};
$self->{ClassB} = ClassB->new();

bless $self, $class;
return $self
}

sub methodA {
my $obj   = shift;
my $class = ref $obj || die "I was not called like OO\n";
say "Method methodA of class $class, property Ap1 is $obj->{Ap1}";
}

1;}# END OF CLASS


BEGIN  {
package ClassB;
our @ISA     = ();
our $VERSION = '1.0';

sub new {
my $class = ref shift || __PACKAGE__;
my $self  = { Bp1=>'Bv01', Bp2=>'Bv01' };
bless $self, $class;
return $self
}

sub methodB {
my $obj   = shift;
my $class = ref $obj || die "I was not called like OO\n";
say "methodB, class $class property Bp1 is $obj->{Bp1}";
}

1;}# END OF CLASS



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4310
***************************************


home help back first fref pref prev next nref lref last post