P
peterkayatwork
I have an object (using standard AUTOLOAD from perltoot) that I want to
pass a coderef to and be able to run the coderef from.
If I do this:
new {
.... # standard object creation from perltoot
$self->{Sub}=sub { return $self->Real(@_) };
return $self;
};
sub Real
{
my $self=shift;
my $arg=shift;
return "[$arg]\n";
}
then I can call it via:
print &{$object->Sub}("Hi");
and get
[Hi]
Few questions:
1. Is this a Bad Way To Do It?
2.
This doesn't work:
$self->{Sub}=\&{$self->Real};
Why not?
The error I get is:
Use of inherited AUTOLOAD for non-method Object::Hi() is deprecated at
Object.t line 22.
Really terribly helpful, isn't it? I can do stuff in Perl, but having
a super-duper handle on WTF the AUTOLOAD stuff is doing with coderefs
is a bit beyond me
If anyone has a good answer for why this is happening, I'd love it. If
anyone has a good suggestion for which FM to read, I'll do so.
3. Is there a way to set $self->{Sub} without using 'sub'?
Thanks,
--Peter
peterkayatwork (at) yahoo.com
pass a coderef to and be able to run the coderef from.
If I do this:
new {
.... # standard object creation from perltoot
$self->{Sub}=sub { return $self->Real(@_) };
return $self;
};
sub Real
{
my $self=shift;
my $arg=shift;
return "[$arg]\n";
}
then I can call it via:
print &{$object->Sub}("Hi");
and get
[Hi]
Few questions:
1. Is this a Bad Way To Do It?
2.
This doesn't work:
$self->{Sub}=\&{$self->Real};
Why not?
The error I get is:
Use of inherited AUTOLOAD for non-method Object::Hi() is deprecated at
Object.t line 22.
Really terribly helpful, isn't it? I can do stuff in Perl, but having
a super-duper handle on WTF the AUTOLOAD stuff is doing with coderefs
is a bit beyond me
If anyone has a good answer for why this is happening, I'd love it. If
anyone has a good suggestion for which FM to read, I'll do so.
3. Is there a way to set $self->{Sub} without using 'sub'?
Thanks,
--Peter
peterkayatwork (at) yahoo.com