summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorNick Ing-Simmons <Nick.Ing-Simmons@tiuk.ti.com>1996-11-21 15:47:46 +0000
committerChip Salzenberg <chip@atlantic.net>1996-11-26 20:48:00 +1200
commit6f08146e2c3ab87e9f70e612981a0771a8acb8fb (patch)
treeebe607293fe73cc1001db8c65af8e7c37e4299dd /universal.c
parentbda0c67a7644b9c34d42b0e8ff4327d6d677133f (diff)
downloadperl-6f08146e2c3ab87e9f70e612981a0771a8acb8fb.tar.gz
"static" call to UNIVERSAL::can
Is there some reason why 'can' does not allow a class name, but (silently) insists on an instance? I wanted to do this : sub Construct { my $class = (caller(0))[0]; if ($class->can('Something')) { ... } else { ... } } can just returns undef in this case, even if class has method in question. Anyone object to a patch? p5p-msgid: <199611211407.OAA14645@pluto> private-msgid: <199611211547.PAA15878@pluto>
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/universal.c b/universal.c
index ea797aea28..476b60d3c0 100644
--- a/universal.c
+++ b/universal.c
@@ -134,6 +134,7 @@ XS(XS_UNIVERSAL_can)
SV *rv;
GV *gv;
CV *cvp;
+ HV *pkg = NULL;
if (items != 2)
croak("Usage: UNIVERSAL::can(object-ref, method)");
@@ -142,8 +143,17 @@ XS(XS_UNIVERSAL_can)
name = (char *)SvPV(ST(1),na);
rv = &sv_undef;
- if(SvROK(sv) && (sv = (SV*)SvRV(sv)) && SvOBJECT(sv)) {
- gv = gv_fetchmethod(SvSTASH(sv), name);
+ if(SvROK(sv)) {
+ sv = (SV*)SvRV(sv);
+ if(SvOBJECT(sv))
+ pkg = SvSTASH(sv);
+ }
+ else {
+ pkg = gv_stashsv(sv, FALSE);
+ }
+
+ if (pkg) {
+ gv = gv_fetchmethod(pkg, name);
if(gv && GvCV(gv)) {
/* If the sub is only a stub then we may have a gv to AUTOLOAD */