NAME

overload::eval - Hooks the native string eval() function

SYNOPSIS

use overload::eval 'my_callback';
sub my_callback { print and eval for $_[0] }

sub rot13 {
    local $_ = shift;
    tr[A-Za-z][N-ZA-Mn-za-m];
    return $_;
}
eval(rot13('cevag "Uryyb jbeyq!\a"'));

DESCRIPTION

This module hooks the native eval() function and sends it to your function instead. The eval() function operates normally within your function.

This module requires user pragmas which are a feature present only in 5.9+.

Using this module is simplicity itself. If you've declared the hook, any uses of string eval in that lexical scope are going to be redirected to the function you named.

{
    use overload::eval;
    eval '...';
}
sub eval {
    # eval goes here
}

If you declare a hook name, execution is redirected to that named function instead of eval.

{
    use overload::eval 'hook';
    eval '...';
}
sub hook {
    # eval goes here because we declared 'hook'
}

DISPELLING MAGIC

This module overloads eval() only with the lexical scope you've requested. To avoid triggering this module, either create a new lexical scope or just disable the overloading.

{
  use overload::eval;
  eval '...'; # Overloaded;
}
eval '...'; # NOT overloaded

Or...

use overload::eval;
eval '...'; # Overloaded;

no overload::eval;
eval '...'; # NOT overloaded.

SEE ALSO

This module does not overload the block form of eval. Sorry. That's an entirely different kind of technology.

eval { ... };

AUTHOR

Joshua ben Jore - jjore@cpan.org

LICENSE

The standard Artistic / GPL license most other perl code is typically using.