From: Branden [mailto:[EMAIL PROTECTED]]
> 
> try to define a method in package bar and try to call it
> from $bar, like $bar->foo. Won't work either, you have
> to ${$bar}->foo. Overloading should loose the magic
> in the same sense that the method should not be called.

No, $bar->asString and $baz->asString both work. They produce:

Hello World


> > package bar;
> > @ISA = qw(foo);
> > sub new {  bless \my $key; \$key }
> 
> You return a reference to the object...

No, it returns an object reference... Try it.

 
> Try printing $$bar, it will work...

No, it doesn't. $$bar is an undefined scalar.


sub new { my $ref = \ my $key; bless $ref; $ref }
  and
sub new { bless \ my $key; \$key; }
 
Both return an object reference. The former has magic, the latter does not.

I'm sorry... I didn't mean to start an off-topic thread. Unless someone can
find a way to shoe-horn in a discussion of language or internals magic
handling for Perl6?  Is there really no substantial documentation anywhere
on magic? I suppose that is why it is called magic, eh?


package foo;
use overload '""' => 'asString';
sub asString { 'Hello World' }

package bar;
@ISA = qw(foo);
sub new {  bless \my $key; \$key }

package baz;
@ISA = qw(foo);
sub new { my $ref = \ my $key; bless $ref; $ref }

package main;
my ($bar, $baz);
$bar = bar::->new();
$baz = baz::->new();

print "\$bar            $bar\n";
print "\$baz            $baz\n";
print "\$bar->asString  ", $bar->asString, "\n";
print "\$baz->asString  ", $baz->asString, "\n";
print "\$\$bar          ", $$bar, "\n";

Results In:
$bar            bar=SCALAR(0x1bbfc9c)
$baz            Hello World
$bar->asString  Hello World
$baz->asString  Hello World
$$bar

Reply via email to