[Israel.pm] bless and AUTOLOAD
Gabor Szabo
szabgab at gmail.com
Tue Sep 25 07:58:41 PDT 2007
Have you tried to print $AUTOLOAD in the AUTOLOAD function?
You will notice that you have to declrae it using "our" not "my'
and then it is called when the DESTROY method of the package is called
so you need to create a
sub DESTROY {
}
to avoid calling AUTOLOAD on object destruction.
Gabor
On 9/25/07, Yona Shlomo <yona at cs.technion.ac.il> wrote:
> Hello,
>
> I have a strange collision using bless and AUTOLOAD.
>
> For example, here a simple Perl script, t.pl, which
> demostrates my problem:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Data::Dumper;
>
> my $t=T->new();
>
> package T;
>
> my $AUTOLOAD;
>
> sub new {
> my ($class, %arguments) = @_;
> bless {}, $class;
> }
>
> sub AUTOLOAD {
> print "why am I in AUTOLOAD?!\n";
> }
>
>
> Surprisingly, for me, when I run t.pl I get:
> why am I in AUTOLOAD?!
>
> So, why am I executing code in AUTOLOAD?
>
> Apparently the $class is to blame in the bless statement,
> but I don't know why and I don't know how to avoid this.
>
> Anyone?
>
> --
> Shlomo Yona
> yona at cs.technion.ac.il
> http://yeda.cs.technion.ac.il/~yona/
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
--
Gabor Szabo
http://www.szabgab.com/
Perl Training in Israel http://www.pti.co.il/
More information about the Perl
mailing list