Skip to content

Nonexistent::Module->import() gives no error #19410

@jimav

Description

@jimav

Nonexistent::Module->import() silently succeeds. Expecting an error like

Can't locate object method "import" via package "Nonexistent::Module" (perhaps you forgot to load "Nonexistent::Module"?)

The docs say import is an ordinary method and not builtin, but that doesn't seem to be entirely true. I think this is a bug (calling any method on a non-existent object or class should result in an error);

if it can not be fixed, then I suggest updating the perlfunc entry for 'import' to explain what is happening.

#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;

$Data::Dumper::Terse = 1;

print "BEFORE:", Dumper(\%Misspelled::);
print "AGAIN :", Dumper(\%Misspelled::);

Misspelled->import();            # NO error

print "AFTER :", Dumper(\%Misspelled::);

Misspelled->othermethod(); # error as expected

Output:

BEFORE:{}
AGAIN :{}
AFTER :{
  'import' => *Misspelled::import
}
Can't locate object method "othermethod" via package "Misspelled" at /tmp/test.pl line 14.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions