summaryrefslogtreecommitdiff
path: root/t/op/universal.t
diff options
context:
space:
mode:
authorTony Bowden <tony@kasei.com>2001-08-25 15:58:17 +0100
committerAbhijit Menon-Sen <ams@wiw.org>2001-08-25 22:46:13 +0000
commit39d11b7fff60fb4dbe9c17fee36ce5399b4376d8 (patch)
tree211bfd70f8b07818dce3f823e3223b86026dedf0 /t/op/universal.t
parent04b85669c399942716cc222829b1dae05a1ed7c2 (diff)
downloadperl-39d11b7fff60fb4dbe9c17fee36ce5399b4376d8.tar.gz
Re: 'can' with undefined subs
Message-Id: <20010825145817.A11788@soto.kasei.com> (Applied with minor modifications.) p4raw-id: //depot/perl@11752
Diffstat (limited to 't/op/universal.t')
-rwxr-xr-xt/op/universal.t16
1 files changed, 10 insertions, 6 deletions
diff --git a/t/op/universal.t b/t/op/universal.t
index 23c616c2b1..b6596a3c95 100755
--- a/t/op/universal.t
+++ b/t/op/universal.t
@@ -24,7 +24,8 @@ package Female;
package Alice;
@ISA=qw(Bob Female);
-sub drink {}
+sub sing;
+sub drink { return "drinking " . $_[1] }
sub new { bless {} }
$Alice::VERSION = 2.718;
@@ -44,8 +45,9 @@ $Alice::VERSION = 2.718;
package main;
-my $i = 2;
-sub test { print "not " unless shift; print "ok $i\n"; $i++; }
+{ my $i = 2;
+ sub test { print "not " unless shift; print "ok $i\n"; $i++; }
+}
$a = new Alice;
@@ -61,11 +63,13 @@ test ! $a->isa("Male");
test ! $a->isa('Programmer');
-test $a->can("drink");
-
test $a->can("eat");
-
test ! $a->can("sleep");
+test my $ref = $a->can("drink"); # returns a coderef
+test $a->$ref("tea") eq "drinking tea"; # ... which works
+test $ref = $a->can("sing");
+eval { $a->sing };
+test $@; # ... but not if no actual subroutine
test (!Cedric->isa('Programmer'));