package Object;
{
# pow does not require an object data
sub pow
{
my $val = shift;
my $pow = shift;
return $val ** $pow;
}
}
1;
####
use Object
Object::pow( 2, 2 );
####
use Object 'pow';
pow( 2,2 );
####
Object->pow(2,2);
Object::pow(2,2);
my $obj = Object->new();
$obj->pow(2,2);
pow(2,2); # Exported or internal method call
####
sub rmvObjRef
{
my $package_name = shift;
my $param1 = ref( $_[ 0 ] ) || $_[ 0 ];
# If param1 holds the name of the class / package
# remove it from the arguments.
if ( $param1 eq $package_name ) {
shift @_;
}
return @_;
}
####
shift if ref $_[0] eq __PACKAGE || $_[0] eq __PACKAGE__;
####
@_ = rmvObjRef( __PACKAGE__, @_ );
####
package NumObject;
sub addObjects
{
@_ = rmvObjRef( __PACKAGE__, @_ );
# Just an example, Obviously an overloaded '+'
# op could achieve this.
return NumObject + NumObject;
}
####
my $num1 = NumObject->new();
my $num2 = NumObject->new();
NumObject::addObjects( $num1, $num2 );