I'd call it a bug - I can't see any reason that one might want to have that as a feature. It still does it with 5.7.2 but I can't see anywhere obvious in the code that it might be done deliberately. I'd report it using perlbug if I were you :) I might even have worked out why it happens by the time I get home :)
Updated Later :
OK, I've got a basic feel for what is going on here now. Firstly it happens for all references, not just CODEREFs. You will notice that when simply accessing the variable it will call the FETCH as expected - it is only when you attempt to dereference that it all goes wrong. You can see this from the following code :
BEGIN
{
package Testtie;
use Tie::Scalar;
use strict;
sub TIESCALAR {
my $class = shift;
my $var = shift;
bless \$var, $class;
}
sub FETCH {
my ( $self ) = @_;
print "FETCHING ${$self}\n";
return ${$self};
}
sub STORE {
my $self = shift;
${$self} = shift;;
print "STORING ${$self}\n";
}
}
my $f;
tie $f, 'Testtie';
$f = 'foo';
print $f,"\n";
$f = \'foo';
print $f,"\n";
print ref($f),"\n";
print ${$f},"\n";
$f = sub {return "running sub\n"};
print $f,"\n";
print ref($f),"\n";
print &{$f},"\n";
Which will output something like:
STORING foo
FETCHING foo
foo
STORING SCALAR(0x811a3ec)
FETCHING SCALAR(0x811a3ec)
SCALAR(0x811a3ec)
FETCHING SCALAR(0x811a3ec)
SCALAR
foo
STORING CODE(0x811a398)
FETCHING CODE(0x811a398)
CODE(0x811a398)
FETCHING CODE(0x811a398)
CODE
running sub
So it looks like like the bit of code that is doing the dereferencing is not respecting the tied magic of the variable and is going straight to the RV to get the ,er, value ... because this value is stored in there whether it is tied or not.
It looks even more like a bug now but I am still not sure which bit of sv.c is responsible ... I'm going to take it up on p5p now ....
/J\
|