warnings::method - Produces warnings if methods are called as functions


warnings-method documentation Contained in the warnings-method distribution.

Index


Code Index:

NAME

Top

warnings::method - Produces warnings if methods are called as functions

VERSION

Top

This document describes warnings::method version 0.10

SYNOPSIS

Top

    use warnings::method;         # installs the check routine lexically
    use warnings::method -global; # or installs it globally
	use warnings 'syntax';        # enables the check routine

    package Foo;
    sub bar :method{
	# ...
    }

    Foo->bar(); # OK

    # the following cases warnings "Method Foo::bar() called as a function"

    Foo::bar();                  # WARN

    my $method_ref = \&Foo::bar; # WARN

    sub f{
        goto &Foo::bar;          # WARN
    }

DESCRIPTION

Top

You shouldn't call a method as a function, e.g. UNIVERSAL::isa($o, 'ARRAY'). It's considered harmful, because such code doesn't call overridden methods in any classes. This pragmatic module produces warnings if methods are called as functions. Here, methods are subroutines declared with the :method attribute.

This module scans the compiled syntax tree, checks function calls and produces warnings when dangerous function calls are detected. All the processes finish in compile time, so this module has no effect on run-time behavior.

The UNIVERSAL::isa and UNIVERSAL::can distributions are modules based on the same concept, but they produce warnings at run time.

INTERFACE

Top

use warnings::method or use warnings::method -lexical

Installs the method check routine with lexical scope.

Note that the lexicality is limited before 5.10.0.

use warnings::method -global

Installs the method check routine with global scope, where this pragma checks all programs.

use/no warnings 'syntax';

Enables/Disables the method check routine.

Note that the syntax warning is defined by default, so you can always use it even if warnings::method is not loaded.

DEPENDENCIES

Top

Perl 5.8.1 or later, and a C compiler.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests to bug-warnings-method@rt.cpan.org/, or through the web interface at http://rt.cpan.org/.

SEE ALSO

Top

UNIVERSAL.

UNIVERSAL::isa.

UNIVERSAL::can.

perllexwarn.

warnings::unused.

AUTHOR

Top

Goro Fuji <gfuji(at)cpan.org>

LICENSE AND COPYRIGHT

Top


warnings-method documentation Contained in the warnings-method distribution.

package warnings::method;

use 5.008_001;

use strict;

our $VERSION = '0.10';

use XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);

# re-declaration for built-in methods
sub UNIVERSAL::can     :method;
sub UNIVERSAL::isa     :method;

sub import{
	shift;
	if(@_){
		_set_mode(@_);
	}

	$^H |= 0x00020000; # HINT_LOCALIZE_HH
	$^H{(__PACKAGE__)} = 1;

	return;
}

1;
__END__