#! perl
package Foo;

# Copyright (C) 2004-2007, The Perl Foundation.
# $Id: /mirror/trunk/examples/benchmarks/overload.pl 21228 2007-09-12T19:23:12.382514Z paultcochrane  $

use strict;
use warnings;

use overload '*' => \&my_mul, 'fallback' => 1;

sub new {
    my ( $class, $val ) = @_;
    return bless \$val, $class;
}

sub my_mul {
    return ${ $_[0] } * ${ $_[1] };
}

1;

package main;
my $a = Foo->new(7);
my $b = Foo->new(6);
my $r;
for my $i ( 1 .. 500_000 ) { $r = $a * $b }
print "$r\n";

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
