in reply to Two argument bless sometimes ignores the class name?

Well, here's something related I don't quite get that might help. I modified your code somewhat:

use strict; package Foo; sub new { print "Expected class: $_[0]"; bless {} => shift } sub test { print "Actual class: ". ref shift } package main; *Bar:: = \*Foo::; my $x = Bar::new('Bar');

Now as I understand it, this ought to work because that last line is equivalent to my $x = Bar->new. But it doesn't. In fact it returns Undefined subroutine &Bar::new called at - line 9. So that makes me think that somehow doing a typeglob assignment on the symbol-table hash doesn't do what you'd expect it to. I haven't yet found any relevant docs though.

Replies are listed 'Best First'.
Re^2: Two argument bless sometimes ignores the class name?
by stvn (Monsignor) on Jan 07, 2005 at 13:21 UTC
    Errto

    Your example and error message, makes me think that TYPEGLOB aliasing is basically a very shallow operation. Basically that it does not go any deeper than the top level GLOB. If you were to change the alias line to:

    *Bar::new = \*Foo::new;
    I get the following output:
    Expected class: Bar
    So that makes me think that somehow doing a typeglob assignment on the symbol-table hash doesn't do what you'd expect it to.
    But you aren't doing it on the symbol table hash, you are doing it on the TYPEGLOB. Although oddly enough, if you do this:
    %Bar:: = %Foo::; my $x = Bar::new('Bar');
    I get the same error you got with your example:
    Undefined subroutine &Bar::new
    Now that is something I wouldn't expect to happen.

    -stvn