We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

objects

perlperl
perlperl asked
on
Medium Priority
219 Views
Last Modified: 2010-03-05
package test;

sub new {
  return undef if ( !defined $this->{NAME} );
}
sub createNames {
}

sub displayNames {
}

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


package test1;

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $this = {};
  bless($this, $class);
  my %hash = @_;

  $this->{ID}             =  $hash{ID} ;
  $this->{OBJECT}          = ### this should be object reference to package test.
  return undef if ( !defined $this->{OBJECT} );
}

sub print {

}

--------------------------------------------------------------------------------------------
package test2;
use base 'test1';
sub new {
  my $proto       = shift;
  my $class       = ref($proto) || $proto;
  my %hash      = @_;
  my $this        = {};
  bless($this, $class);
  my $this             = $class->SUPER::new(%hash_args);  
   
  return $this;
}

sub disp {
### how can i access displayNames() of class "test" here
}

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


example.pl

use test2;
my $obj = test2->new(ID=>"1234");
### how can $obj access the method displ of module "test2"
### how can i call displayName of "test"
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
package test1;

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $this = {};
  bless($this, $class);
  my %hash = @_;

  $this->{ID}             =  $hash{ID} ;
  $this->{OBJECT}          = bless {},"test";
  return undef if ( !defined $this->{OBJECT} );
  return $this;
}


use test2;
my $obj = test2->new(ID=>"1234");
### how can $obj access the method displ of module "test2"
$obj->disp;
### how can i call displayName of "test"
$obj->{OBJECT}->displayNames;

Author

Commented:
Ozo,
what will be
sub disp  { }   in package "test2"
also, will thre be any change in new() of test2
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
sub disp {
    my $self=shift;
    print $self->{OBJECT}->displayNames();
### how can i access displayNames() of class "test" here
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
ok..will try later and let you know....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.