There are two ways to solve your problem:
1. in your class2, you specifically export the methods that you want to be
used in other classes; or
2. you inherent the methods from class2 into your class1.
Here are hows:
Method 1: in your class2:
require Exporter;
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
our @EXPORT = qw(m2 );
our @EXPORT_OK = qw( );
our %EXPORT_TAGS = ( );
Method 2: Without changing your class2, you can do this in your class1:
use Class1::Class2;
our @ISA=qw(Class1::Class2);
Hope this helps.
Hanming Tu
"Matthias Eichner" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> Hello,
>
> I created two classes, class1 and class2. In a method (m1) of class 1 I
> instanciate an object of class2 and want to access a method (m2) of this
> class (class2), But I always get an error that the object method (m2)
> cannot be located via package class2:
> Can't locate object method "new" via package "class2" at class1.pm line
16.
>
> What I am doing wrong?
>
> Thanx in advance,
> Matthias
>
> Here is the example code:
>
> /class1.pm:
> -------
> package class1;
> use class1::class2;
> use strict;
>
> sub new {
> my $proto = shift;
> my $class = ref($proto) || $proto;
> my $self = {};
> $self->{TABLE} = [];
> bless($self,$class);
> return $self;
> }
>
> sub m1 {
> my $self = shift;
> my $ref=class2->new();
> push(@{$self->{TABLE}},$ref);
> $ref->m2();
> }
>
> 1;
>
> /class1/class2.pm:
> ------------
> package class1::class2;
> use strict;
>
> sub new {
> my $proto = shift;
> my $class = ref($proto) || $proto;
> my $self = {};
> $self->{GREETING} = "Hi folks.";
> bless($self,$class);
> return $self;
> }
>
> sub m2 {
> my $self = shift;
> printf "\n%s\n", $self->{GREETING};
> }
>
> 1;
>
> /test.pl:
> ----
> #!/usr/bin/perl -w -I.
>
> use class1;
> use strict;
>
> my $ref=class1->new();
>
> $ref->m1();
>
> exit 0;
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]