Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Object::InsideOut and $obj->SUPER (fixed)

by glide (Pilgrim)
on Nov 02, 2007 at 17:32 UTC ( [id://648700]=perlquestion: print w/replies, xml ) Need Help??

glide has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I'm trying to create a new class based in a class that use Object::InsideOut. But the new class can't use the Object::InsideOut.

In the child class I do:

sub new { my ($class,%args) = @_; my $new_object = $class->SUPER::new(%args); ....
but, apparently, the new of the base class it's never called.

What I'm missing?

many thanks

execution and code ...

$ perl t2.pl I'm in the child_class new my super is class_insideout id: 1 Use of uninitialized value in array element at /home/glide/develop/per +l_tests/Object_InsideOut/class_insideout.pm line 27. Use of uninitialized value in concatenation (.) or string at /home/gli +de/develop/perl_tests/Object_InsideOut/class_insideout.pm line 27. name: Use of uninitialized value in array element at /home/glide/develop/per +l_tests/Object_InsideOut/class_insideout.pm line 28. Use of uninitialized value in concatenation (.) or string at /home/gli +de/develop/perl_tests/Object_InsideOut/class_insideout.pm line 28. address:
base class code
package class_insideout; use strict; use warnings; { use Object::InsideOut; my @name :Field :Arg(Name => 'name', 'Mandatory' => 1) :Std(Name => 'name'); my @address :Field :Arg(Name => 'address', 'Mandatory' => 1) :Std(Name => 'address'); sub _init :Init{ my ($self,$args) = @_; warn("I'm in the ".__PACKAGE__ ." _init\n"); return; } sub write { my ($self) = @_; print "name: ". $name[$$self] ."\n"; print "address: ". $address[$$self] ."\n"; } } 1;
child class code
package child_class; use strict; use warnings; use Class::Std::Utils; use base qw(class_insideout); { my %num_ID; sub new { my ($class, %args) = @_; my $new_object = $class->SUPER::new(%args); warn("I'm in the ".__PACKAGE__." new\n"); warn("my super is @child_class::ISA \n"); $num_ID{ident $new_object} = $args{id}; return $new_object; } sub write { my ($self) = @_; print "id: ". $num_ID{ident $self} ."\n"; $self->SUPER::write(); return; } } 1;
script code
use strict; use warnings; use FindBin; use lib $FindBin::Bin; use child_class; my $person = child_class->new(id=>1,name=>'aaa',address=>'bbb') or die +(); $person->write();

Replies are listed 'Best First'.
Re: Object::InsideOut and $obj->SUPER
by duckyd (Hermit) on Nov 02, 2007 at 22:00 UTC
    Your child class must
    use Object::InsideOut qw(class_insideout);
    instead of
    use base qw(class_insideout);
    From the POD:
    Sub-classes (child classes) inherit from base classes (parent classes) by telling Object::InsideOut what the parent class is: package My::Sub; { use Object::InsideOut qw(My::Parent); ... } <snip> Object::InsideOut acts as a replacement for the "base" pragma: It loads the parent module(s), calls their "->import()" methods, and sets up the sub-class's @ISA array. Therefore, you should not "use base .. +." yourself
      I thought that the use of
      use Object::InsideOut qw(My::Parent);
      was only for classes of the type Object::InsideOut. And I wanted a regular class (eventually hash based). But it works! Thanks.

      This is a drawback, imho, of using Object::InsideOut. For example, if you put a class in the cpan, based in the Object::InsideOut, the use of the class it's different from the expected.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://648700]
Approved by kyle
Front-paged by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found