#!/usr/bin/perl -w use strict; # Our base, or super class package Foo; sub new { bless {}, shift; } # The subclass Bar inherits from Foo package Bar; use base 'Foo'; # The main package package main; # Instantiate an object of type Bar: my $obj = Bar->new(); # Three different kinds of tests, to see what type the object is: print "Using ref to test which object type:\n"; print "\$obj is Bar\n" if(ref $obj eq 'Bar'); print "\$obj is Foo\n" if(ref $obj eq 'Foo'); print "Using UNIVERSAL::isa:\n"; print "\$obj is Bar or subclass of Bar\n" if(UNIVERSAL::isa($obj,'Bar')); print "\$obj is Foo or subclass of Foo\n" if(UNIVERSAL::isa($obj,'Foo')); print "Using object method isa:\n"; print "\$obj is Bar or subclass of Bar\n" if($obj->isa('Bar')); print "\$obj is Foo or subclass of Foo\n" if($obj->isa('Foo'));