"... anyone who names their package "0" is going to asking for trouble!"
Naming a package 0 is a fatal, compilation error:
$ perl -e 'package X;' $ perl -e 'package 0;' syntax error at -e line 1, near "package 0;" Execution of -e aborted due to compilation errors.
The problem is likely to occur where, in some code completely separate from yours, someone writes '$x->your_method()' when, perhaps, '$y->your_method()' was intended.
I had some difficulty coming up with an example. Here's some valid, albeit highly contrived, code to demonstrate the concept.
I've used a common alias of mine to show code validity:
$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -MCarp::Always -E +'
$ perle ' package X { use Scalar::Util "blessed"; sub new { bless {}, __PACKAGE__; } sub meth1 { say "meth1: [", ref $_[0], "]" } sub meth2 { say "meth2: [", blessed $_[0] // "undef", "]" } sub meth3 { say "meth3: [", defined blessed $_[0], "]" } }; package main; my $x = 0; my $y = X::->new(); $x->X::meth1(); $x->X::meth2(); $x->X::meth3(); $y->X::meth1(); $y->X::meth2(); $y->X::meth3(); ' meth1: [] meth2: [undef] meth3: [] meth1: [X] meth2: [X] meth3: [1]
The 'package X;' is intended to represent your code; the 'package main;' (although quite superfluous here) is intended to represent "some code completely separate from yours".
— Ken
In reply to Re^4: Calling module function from within a blessed module
by kcott
in thread Calling module function from within a blessed module
by Bod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |