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
346 changes: 170 additions & 176 deletions lib/warnings.pm

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pod/perldeprecation.pod
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Category: "deprecated::unicode_property_name"

=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). As of
Perl version 5.39.2 calling such a method I<with> an argument will
trigger a warning, and in Perl version 5.44 this warning will be
upgraded to an error. (Calling such a method with no arguments at all
will always be safe.)
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"

Expand Down
20 changes: 7 additions & 13 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1339,20 +1339,14 @@ 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 ("%s"%s)
via package "%s" (Perhaps you forgot to load the package?)

(D deprecated::missing_import_called_with_args) 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 succeded due to a case insensitive
file system.
=item Attempt to call undefined %s method with arguments via package
"%s" (Perhaps you forgot to load the package?)

Another common reason this may happen is when mistakenly attempting to
import or unimport a symbol from a class definition or package which
does not use C<Exporter> or otherwise define its own C<import> or
C<unimport> method.
(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 succeded due to a case insensitive
file system.

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

Expand Down
3 changes: 2 additions & 1 deletion 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.75';
$VERSION = '1.76';

BEGIN {
require './regen/regen_lib.pl';
Expand Down Expand Up @@ -189,6 +189,7 @@ BEGIN
# the experiments were successful (or abandoned),
# so no warning bit is needed anymore
my %NO_BIT_FOR = map { ( uc $_ => 1, $_ => 1 ) } qw(
deprecated::missing_import_called_with_args
deprecated::smartmatch
experimental::lexical_subs
experimental::postderef
Expand Down
35 changes: 18 additions & 17 deletions t/op/universal.t
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,26 @@ my $x = {}; bless $x, 'X';
ok $x->isa('UNIVERSAL');
ok $x->isa('UNIVERSAL');


{
my $err;
$SIG{__WARN__}= sub { die $_[0] };
eval { Some::Package->import("bar") };
my $err = $@;
$err=~s!t/op!op!;
is $err, "Attempt to call undefined import method with arguments (\"bar\")"
. " via package \"Some::Package\" (Perhaps you forgot to load"
. " the package?) at op/universal.t line 203.\n";
eval { Some::Package->unimport(1.234) };
$err = $@;
$err=~s!t/op!op!;
is $err, "Attempt to call undefined unimport method with arguments (\"1.234\")"
. " via package \"Some::Package\" (Perhaps you forgot to load"
. " the package?) at op/universal.t line 209.\n";

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
1 change: 1 addition & 0 deletions t/porting/diag.t
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ while (<$diagfh>) {
&& !$entries{$cur_entry}{cattodo}) {
my $data_line= $entries{$cur_entry}{todo_line};
TODO: {
no warnings 'once';
local $::TODO = "Remove the TODO entry \"$cur_entry\" from DATA "
. "at $0 line $data_line as it is already in $pod near line $.";
ok($cur_entry);
Expand Down
12 changes: 4 additions & 8 deletions universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,10 @@ 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"))
ck_warner_d(packWARN(WARN_DEPRECATED__MISSING_IMPORT_CALLED_WITH_ARGS),
"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)));
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)));
}
XSRETURN_EMPTY;
}
Expand Down
21 changes: 8 additions & 13 deletions warnings.h

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

Loading