use strict;
use TT;
sub test
{
print "I am test\n";
}
if(exists &{test}) # checing main function using exists &{fun_name})
{
print "Yes found\n";
}
else
{
print "Not found\n";
}
if(defined &{'test'}) # checing main function using exists &{'fun_name'}
{
print "Yes found\n";
}
else
{
print "Not found\n";
}
if(defined &{'main::test'}) # checing main function using defined &{'main::fun_name'}
{
print "Yes found\n";
}
else
{
print "Not found\n";
}
my $t=TT->new();
if($t->can('tprint')) # checing package function using exists &{'fun_name'}
{
print "Yes found\n";
}
else
{
print "Not found\n";
}
if(defined &{'TT::tprint1'}) # checing main function using exists &{'Module::fun_name'}
{
print "Yes found\n";
}
else
{
print "Not found\n";
}
__END__
package TT;
sub new
{
my($class, %args) = @_;
my $self = bless({}, $class);
my $target = exists $args{target} ? $args{target} : "world";
$self->{target} = $target;
return $self;
}
sub tprint
{
print "I am tprint\n";
}
sub tprint1
{
print "I am tprint1\n";
}
1;
No comments:
Post a Comment