develooper Front page | perl.perl5.porters | Postings from January 2005

Two argument bless sometimes ignores the class name?

Thread Next
From:
publiustemp-p5p3
Date:
January 6, 2005 20:07
Subject:
Two argument bless sometimes ignores the class name?
Message ID:
20050107040659.47482.qmail@web60804.mail.yahoo.com
Hi all,

I've been looking for the answer to this, but I can't find it.  I'm not
submitting a Perl bug report because I'm not sure if this is a bug or
Yet Another Perl Feature I Don't Know.

  #!/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 expect ref to return 'Bar', but
instead it returns 'Foo'.  Why is that?

Cheers,
Ovid

=====
Silence is Evil            http://users.easystreet.com/ovid/philosophy/decency.html
Ovid                       http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About