Next Tricks of the Wizards 152

Overloading: Y2K Detection Example

        package y2k;
        ...
        use overload 'nomethod' => \&default;
        ...
        sub default {
          my ($y2k, $arg, $rev, $op) = @_;
          my $y = $y2k->{YEAR};
          my $expr = $rev ? "$arg $op $y" : "$y $op $arg";
          eval $expr;
        }


Next Copyright © 2003 M. J. Dominus