The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Devel::DidYouMean - Intercepts failed function and method calls, suggesting the nearest matching alternative.

VERSION

version 0.04

SYNOPSIS

    #!/usr/bin/env perl

    # somescript.pl
    use Data::Dumper;
    use Devel::DidYouMean;

    print Dumpr($data); # wrong function name

*Run the code*

    $ somescript.pl
    Undefined subroutine 'Dumpr' not found in main. Did you mean Dumper? at somescript.pl line 7.

Or as a one liner:

    $ perl -MData::Dumper -MDevel::DidYouMean -e 'print Dumpr($data)'
    Undefined subroutine 'Dumpr' not found in main. Did you mean Dumper? at -e line 1.

Or trap the error and extract the matching subs

    use Devel::DidYouMean;
    use Try::Tiny;

    try
    {
        sprintX("", $text); # boom
    }
    catch
    {
        my $error_msg = $_;
        my @closest_matching_subs = @$Devel::DidYouMean::DYM_MATCHING_SUBS;

        # do something cool here
    }

DESCRIPTION

Devel::DidYouMean intercepts failed function and method calls, suggesting the nearest matching available subroutines in the context in which the erroneous function call was made.

WARNING

This library is experimental, on load it exports an AUTOLOAD subroutine to every namespace in the symbol table. In version 0.03 and higher, this library must be loaded using use and not require. In version 0.04 and higher it will not overwrite an existing AUTOLOAD in a namespace.

THANKS

This module was inspired by Yuki Nishijima's Ruby gem did_you_mean.

Chapter 9 "Dynamic Subroutines" in Mastering Perl second edition by brian d foy was a vital reference for understanding Perl's symbol tables.

SEE ALSO

Symbol::Approx::Sub is a similar module that catches invalid subroutine names and then executes the nearest matching subroutine it can find. It does not export AUTOLOAD to all namespaces in the symbol table.

AUTHOR

David Farrell <sillymoos@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by David Farrell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.