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
In reply to Attribute::Handler's behaviors with use vs require by rpg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |