in reply to When I use "can"

Do you really need to check whether import exists?
Module -> import (args...) if Module -> can ("import");
Hmmm... This doesn't create any errors:
$perl -e 'Foo->import' $
whereas this does generate an error:
$ perl -e 'Foo->bar' Can't locate object method "bar" via package "Foo" (perhaps you forgot + to load "Foo"?) at -e line 1. $
This implies to me that you can call the import method without having to worry whether it exists or not. perlfunc states with use:
If no "import" method can be found then the call is skipped.
That can construed as to only applying to use, so maybe the wording of the documentation should be changed.

Liz

Replies are listed 'Best First'.
Re: Re: When I use "can"
by ysth (Canon) on Apr 08, 2004 at 10:20 UTC
    If no "import" method can be found then the call is skipped.

    That can construed as to only applying to use, so maybe the wording of the documentation should be changed.

    It's documented in perlsub/Autoloading:
    (As an exception, a method call to a nonexistent "import" or "unimport" method is just skipped instead.)
    (The unimport case is new as of 5.6.1.)