Skip to content
This repository
Browse code

Merge pull request #462 from exodist/master

Fix can() so that it will nto die when called on a package
  • Loading branch information...
commit 2dcdf47d702cec85834be4227b8bbf56fdc2e82a 2 parents 3d24e59 + 864df35
Tatsuhiko Miyagawa miyagawa authored

Showing 2 changed files with 17 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  lib/Plack/Util.pm
  2. +15 0 t/Plack-Util/can.t
3  lib/Plack/Util.pm
@@ -309,7 +309,8 @@ package Plack::Util::Prototype;
309 309
310 310 our $AUTOLOAD;
311 311 sub can {
312   - $_[0]->{$_[1]};
  312 + return $_[0]->{$_[1]} if Scalar::Util::blessed($_[0]);
  313 + goto &UNIVERSAL::can;
313 314 }
314 315
315 316 sub AUTOLOAD {
15 t/Plack-Util/can.t
... ... @@ -0,0 +1,15 @@
  1 +use strict;
  2 +use warnings;
  3 +use Test::More;
  4 +use Plack::Util;
  5 +
  6 +my $can;
  7 +my $lives = eval { $can = Plack::Util->can('something_obviously_fake'); 1 };
  8 +ok($lives, "Did not die calling 'can' on Plack::Util package with invalid sub");
  9 +is($can, undef, "Cannot do that method");
  10 +
  11 +$lives = eval { $can = Plack::Util->can('content_length'); 1 };
  12 +ok($lives, "Did not die calling 'can' on Plack::Util package with real sub");
  13 +is($can, \&Plack::Util::content_length, "can() returns the sub");
  14 +
  15 +done_testing;

0 comments on commit 2dcdf47

Please sign in to comment.
Something went wrong with that request. Please try again.