Ovid has asked for the wisdom of the Perl Monks concerning the following question:
In Re: Module Naming Dilemma, Anonymous Monk asked why I wasn't simply aliasing typeglobs together for some code I was working on. Ignoring the fact that I wanted to minimize that behavior, I was kind of stumped by the following code snippet:
#!/usr/local/bin/perl -lw use strict; package Foo; sub new { print "Expected class: $_[0]"; bless {} => shift } sub test { print "Actual class: ". ref shift } package main; *Bar:: = \*Foo::; Bar->new->test; Foo::new('Bar')->test;
Both times that test() is called, I would expect ref to return Bar but it instead returns Foo. Why is that?
I (once again) cannot find where this behavior is documented, even though I suspect it is. Frankly, this code does not do what I would expect it to to do.
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two argument bless sometimes ignores the class name?
by bart (Canon) on Jan 07, 2005 at 13:27 UTC | |
by duff (Parson) on Jan 07, 2005 at 15:19 UTC | |
|
Re: Two argument bless sometimes ignores the class name?
by stvn (Monsignor) on Jan 07, 2005 at 05:09 UTC | |
|
Re: Two argument bless sometimes ignores the class name?
by Errto (Vicar) on Jan 07, 2005 at 05:10 UTC | |
by stvn (Monsignor) on Jan 07, 2005 at 13:21 UTC | |
|
Re: Two argument bless sometimes ignores the class name?
by dragonchild (Archbishop) on Jan 07, 2005 at 05:24 UTC | |
|
Re: Two argument bless sometimes ignores the class name?
by !1 (Hermit) on Jan 15, 2005 at 06:42 UTC |