rpg has asked for the wisdom of the Perl Monks concerning the following question:
Now when I call this module using require, and call function foo(), it executes only the foo's print statement.package FOO; use strict; use warnings; use Attribute::Handlers; use base 'Exporter'; our @EXPORT = qw(__RETRY); sub __RETRY : ATTR(CODE) { my ($pkg, $sym, $code) = @_; no warnings 'redefine'; *{ $sym } = sub { my $self = $_[0]; my $result; print ("Executing subroutine\n"); $result = $code->(); if ($result) { print "You Pass\n"; } else { print "You Fail\n"; } } } sub foo : __RETRY { print "Executing Foo\n"; return 1; } 1;
Output:require "FOO.pm"; FOO->import(); FOO::foo();
But then I do the same using use, it does the correct job.Executing Foo
Output:use FOO; FOO::foo();
Actually, in my code I am calling it using require and it's not working. Your help will be highly appreciated!!Executing subroutine Executing Foo You Pass
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attribute::Handler's behaviors with use vs require (optimization)
by tye (Sage) on Jul 10, 2012 at 17:46 UTC | |
|
Re: Attribute::Handler's behaviors with use vs require
by Athanasius (Archbishop) on Jul 10, 2012 at 14:31 UTC | |
by rpg (Novice) on Jul 10, 2012 at 17:09 UTC |