Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/warnings.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions pod/perldeprecation.pod
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ Category: "deprecated::unicode_property_name"

=head2 Perl 5.44

=head3 Calling a missing C<import()> or C<unimport()> method with an argument

Historically calling C<import()> or C<unimport()> on any class which did not
define such a method would be silently ignored. Effectively Perl behaved as
though there was an empty method defined in the C<UNIVERSAL> package (even
when there was no such method actually defined). Beginning with Perl version
5.39.2 (production version 5.40), calling such a method I<with> an argument
triggered a warning, and in Perl version 5.44 this warning became upgraded to
an error. (Calling such a method with no arguments at all will always be
safe.)

Category: "deprecated::missing_import_called_with_args"

=head3 Changing C<use VERSION> while another C<use VERSION> is in scope

A C<use VERSION> declaration has many implicit effects on the surrounding
Expand Down Expand Up @@ -632,7 +619,6 @@ So now C<tie $scalar> will always tie the scalar, not the handle it holds.
To tie the handle, use C<tie *$scalar> (with an explicit asterisk). The same
applies to C<tied *$scalar> and C<untie *$scalar>.


=head1 SEE ALSO

L<warnings>, L<diagnostics>.
Expand Down
19 changes: 12 additions & 7 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1339,15 +1339,20 @@ a string overload and is also not a blessed CODE reference. In short the
C<require> function does not know what to do with the object.
See also L<perlfunc/require>.

=item Attempt to call undefined %s method with arguments via package
"%s" (Perhaps you forgot to load the package?)

(F) You called the C<import()> or C<unimport()> method of a class that has no
such method defined in its inheritance graph, and passed an argument to the
method. This is very often the sign of a misspelled package name in a C<use>
or C<require> statement that has silently succeeded due to a case insensitive
=item Attempt to call undefined %s method with arguments ("%s"%s)
via package "%s" (Perhaps you forgot to load the package?)

(S undef_import) You called the
C<import()> or C<unimport()> method of a class that has no import method
defined in its inheritance graph, and passed an argument to the method.
This is very often the sign of a misspelled package name in a use or
require statement that has silently succeeded due to a case insensitive
file system.

Another common reason this may happen is mistakenly attempting to
import or unimport a symbol from a package which does not use
C<Exporter> or otherwise define its own C<import> or C<unimport> method.

=item Can't locate package %s for @%s::ISA

(W syntax) The @ISA array contained the name of another package that
Expand Down
5 changes: 2 additions & 3 deletions regen/warnings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# This script is normally invoked from regen.pl.

$VERSION = '1.76';
$VERSION = '1.77';

BEGIN {
require './regen/regen_lib.pl';
Expand Down Expand Up @@ -80,8 +80,6 @@ BEGIN
'deprecated::dot_in_inc' => [ 5.025011, DEFAULT_ON],
'deprecated::version_downgrade' => [ 5.035009, DEFAULT_ON],
'deprecated::delimiter_will_be_paired' => [ 5.035010, DEFAULT_ON],
'deprecated::missing_import_called_with_args'
=> [ 5.039002, DEFAULT_ON],
'deprecated::subsequent_use_version' => [ 5.039008, DEFAULT_ON],
}],
'void' => [ 5.008, DEFAULT_OFF],
Expand Down Expand Up @@ -170,6 +168,7 @@ BEGIN
'locale' => [ 5.021, DEFAULT_ON],
'shadow' => [ 5.027, DEFAULT_OFF],
'scalar' => [ 5.035, DEFAULT_OFF],
'undef_import' => [ 5.043, DEFAULT_ON ],

#'default' => [ 5.008, DEFAULT_ON ],
}]};
Expand Down
10 changes: 10 additions & 0 deletions t/lib/warnings/universal
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ my $a = bless [] ;
UNIVERSAL::isa $a, Jim ;
EXPECT
Can't locate package Joe for @Y::ISA at - line 8.
########
use warnings 'undef_import';
Some::Package->import("bar");
EXPECT
Attempt to call undefined import method with arguments ("bar") via package "Some::Package" (Perhaps you forgot to load the package?) at - line 2.
########
use warnings 'undef_import';
Some::Package->unimport(1.234);
EXPECT
Attempt to call undefined unimport method with arguments ("1.234") via package "Some::Package" (Perhaps you forgot to load the package?) at - line 2.
Comment on lines +28 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't test that the warning is enabled by default.

Or that disabling it works.

22 changes: 1 addition & 21 deletions t/op/universal.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN {
require "./test.pl";
}

plan tests => 144;
plan tests => 142;

$a = {};
bless $a, "Bob";
Expand Down Expand Up @@ -196,26 +196,6 @@ my $x = {}; bless $x, 'X';
ok $x->isa('UNIVERSAL');
ok $x->isa('UNIVERSAL');

sub test_undefined_method {
my $method = shift;
my @message_components = (
q|Attempt to call undefined|,
q|method with arguments via package "Some::Package"|,
q|(Perhaps you forgot to load the package?)|,
);
my $message = join ' ' => (
$message_components[0],
$method,
@message_components[1,2],
);
my $pattern = qr/\Q$message\E/;

eval { Some::Package->$method("bar") };
like $@, $pattern, "Got expected pattern for undefined $method";
}

test_undefined_method($_) for (qw| import unimport |);

# This segfaulted in a blead.
fresh_perl_is('package Foo; Foo->VERSION; print "ok"', 'ok');

Expand Down
12 changes: 8 additions & 4 deletions universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,14 @@ XS(XS_UNIVERSAL_import_unimport)
* depends on it has its own "no import" logic that produces better
* warnings than this does. */
if (strNE(class_pv,"_charnames"))
Perl_croak(aTHX_
"Attempt to call undefined %s method with arguments via package "
"%" SVf_QUOTEDPREFIX " (Perhaps you forgot to load the package?)",
ix ? "unimport" : "import", SVfARG(ST(0)));
ck_warner_d(packWARN(WARN_UNDEF_IMPORT),
"Attempt to call undefined %s method with arguments "
"(%" SVf_QUOTEDPREFIX "%s) via package "
"%" SVf_QUOTEDPREFIX " (Perhaps you forgot to load the package?)",
ix ? "unimport" : "import",
SVfARG(ST(1)),
(items > 2 ? " ..." : ""),
SVfARG(ST(0)));
}
XSRETURN_EMPTY;
}
Expand Down
4 changes: 3 additions & 1 deletion warnings.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading