glide has asked for the wisdom of the Perl Monks concerning the following question:
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:
but, apparently, the new of the base class it's never called.sub new { my ($class,%args) = @_; my $new_object = $class->SUPER::new(%args); ....
What I'm missing?
many thanks
execution and code ...
base class 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:
child class codepackage 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;
script codepackage 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;
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 | |
by glide (Pilgrim) on Nov 05, 2007 at 10:08 UTC |