P
Peter Vereshagin
I have a sub in a package and I need to tweak its environment before it to be called.
I supposed I could do it klike this:
*old_sub = *some_sub;
sub some_sub{
$ENV{ FOO } = 'BAR';
&old_sub( @_ );
}
But it doesn't work.
Looking at Sub::Override I can say it is possible but the real thing spoils from me on it source code. I cannot use Sub::Override for this either because I need to use the replaced sub inside the overriding one.
The whole thing is on the sources below:
=== Test07.pm ===
package Test07;
use strict;
use warnings;
use Test09;
sub testing07{
print $Test09::test09."07\n";
}
1;
=== Test08.pm ===
package Test08;
use strict;
use warnings;
1;
package Test07;
use strict;
use warnings;
sub testing07{
print "EFGH"."07\n";
}
1;
package Test11;
use strict;
use warnings;
use base qw/Test07/;
*mod_test07 = *Test07::testing07;
1;
=== Test09.pm ===
package Test09;
use strict;
use warnings;
our $test09 = "ABCD";
1;
=== test10.pl ===
#!usr/bin/perl
use strict;
use warnings;
use lib qw/./;
use Test08;
Test11::mod_test07;
=== output of test10.pl ===
Subroutine testing07 redefined at Test07.pm line 8.
ABCD07
===
The what I need here for Test07 package is:
===
sub testing07{
$Test09::test09 = "EFGH";
some_old_testing07;
}
===
to have "EFGH07" as the output. Is it any way possible? I can achieve this by something like:
===
sub testing07{
$Test09::test09 = "EFGH";
Test11::mod_test07; # the old testing07() is saved here
}
===
but this is a pretty bad style, isn't it?
Thank you.
73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB 12F8 0CE1 4AAC A0E2 6627)
I supposed I could do it klike this:
*old_sub = *some_sub;
sub some_sub{
$ENV{ FOO } = 'BAR';
&old_sub( @_ );
}
But it doesn't work.
Looking at Sub::Override I can say it is possible but the real thing spoils from me on it source code. I cannot use Sub::Override for this either because I need to use the replaced sub inside the overriding one.
The whole thing is on the sources below:
=== Test07.pm ===
package Test07;
use strict;
use warnings;
use Test09;
sub testing07{
print $Test09::test09."07\n";
}
1;
=== Test08.pm ===
package Test08;
use strict;
use warnings;
1;
package Test07;
use strict;
use warnings;
sub testing07{
print "EFGH"."07\n";
}
1;
package Test11;
use strict;
use warnings;
use base qw/Test07/;
*mod_test07 = *Test07::testing07;
1;
=== Test09.pm ===
package Test09;
use strict;
use warnings;
our $test09 = "ABCD";
1;
=== test10.pl ===
#!usr/bin/perl
use strict;
use warnings;
use lib qw/./;
use Test08;
Test11::mod_test07;
=== output of test10.pl ===
Subroutine testing07 redefined at Test07.pm line 8.
ABCD07
===
The what I need here for Test07 package is:
===
sub testing07{
$Test09::test09 = "EFGH";
some_old_testing07;
}
===
to have "EFGH07" as the output. Is it any way possible? I can achieve this by something like:
===
sub testing07{
$Test09::test09 = "EFGH";
Test11::mod_test07; # the old testing07() is saved here
}
===
but this is a pretty bad style, isn't it?
Thank you.
73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB 12F8 0CE1 4AAC A0E2 6627)