# implies:
A->VERSION(1.2);
-=item class()
-
-C<class> returns the class name of its object.
-
-=item is_instance()
-
-C<is_instance> returns true if its object is an instance of some
-class, false if its object is the class (package) itself. Example
-
- A->is_instance(); # False
-
- $var = 'A';
- $var->is_instance(); # False
-
- $ref = bless [], 'A';
- $ref->is_instance(); # True
-
-This can be useful for methods that wish to easily distinguish
-whether they were invoked as class or as instance methods.
-
- sub some_meth {
- my $classname = shift;
- if ($classname->is_instance()) {
- die "unexpectedly called as instance not class method";
- }
- .....
- }
-
=back
B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
# implies:
A->VERSION(1.2);
-=item class()
-
-C<class> returns the class name of its object.
-
-=item is_instance()
-
-C<is_instance> returns true if its object is an instance of some
-class, false if its object is the class (package) itself. Example
-
- A->is_instance(); # False
-
- $var = 'A';
- $var->is_instance(); # False
-
- $ref = bless [], 'A';
- $ref->is_instance(); # True
-
=back
B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
}
static
-XS(XS_UNIVERSAL_is_instance)
-{
- dXSARGS;
- ST(0) = SvROK(ST(0)) ? &sv_yes : &sv_no;
- XSRETURN(1);
-}
-
-static
-XS(XS_UNIVERSAL_class)
-{
- dXSARGS;
- if(SvROK(ST(0)) && SvOBJECT(SvRV(ST(0)))) {
- SV *sv = sv_newmortal();
- sv_setpv(sv, HvNAME(SvSTASH(SvRV(ST(0)))));
- ST(0) = sv;
- }
- XSRETURN(1);
-}
-
-static
XS(XS_UNIVERSAL_VERSION)
{
dXSARGS;
newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
- newXS("UNIVERSAL::class", XS_UNIVERSAL_class, file);
- newXS("UNIVERSAL::is_instance", XS_UNIVERSAL_is_instance, file);
newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);
}