1 2 3 4 5
#!/usr/bin/perl use diagnostics; use URI; my $uri = URI->new("-invalid-input-harhar-")->canonical; my $host = $uri->host;
1
2
3
4
5
6
7
8
9
Can't locate object method "host" via package "URI::_generic" at /tmp/foo.pl
line 5 (#1)
(F) You called a method correctly, and it correctly indicated a package
functioning as a class, but that package doesn't define that particular
method, nor does any of its base classes. See perlobj.
Uncaught exception from user code:
Can't locate object method "host" via package "URI::_generic" at /tmp/foo.pl line 5.
at /tmp/foo.pl line 5
print $uri->host if $uri->can('host');
1 2 3 4 5
#!/usr/bin/perl use diagnostics; use URI; my $uri = URI->new("-invalid-input-harhar-")->canonical; my $host = $uri->path_query;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use strict; use warnings; use diagnostics; my $m = bless{}, 'main'; # Exception fangen eval{ $m->foo; }; if($@){ print $@ } # Uncaught exception from user code: ... # haha, von wegen uncaught!!! # ohne diagnostics: Can't locate object method "foo" via package "main" # das klingt schon viel besser ;)
1 2 3 4 5 6
use strict; use warnings; use diagnostics; my $m = bless{}, "main"; eval{ $m->foo }; if ($@) { say "perl $]: $@" }
1
2
3
4
perl 5.010001: Can't locate object method "foo" via package "main" at -e line 6.
perl 5.012004: Can't locate object method "foo" via package "main" at -e line 6.
perl 5.014002: Can't locate object method "foo" via package "main" at -e line 6.
perl 5.016000: Can't locate object method "foo" via package "main" at -e line 6.