D
Dr.Ruud
*foo = eval "\\$tmp"; die $@ if $@ ;
I never get it why people test $@.
eval "*foo = \\$tmp; 1" or die $@;
And if you are going to die anyway:
*foo = \$tmp;
*foo = eval "\\$tmp"; die $@ if $@ ;
^^^^^^^^^^^^^I never get it why people test $@.
Reflex.
eval "*foo = \\$tmp; 1" or die $@;
And if you are going to die anyway:
*foo = \$tmp;
Yes, thanks I realize that. My point was although it was a loose
"encapsulation" you can come close to faking what 'state' and
'my-variables in a surrounding scope' can do.
In fact, although it's nothing more than a curiosity,
(maybe "curioser and curioser" Alice would say) you could
even tighten it a bit more with an eval:
package MyFoo;
our( $foo, $tmp );
sub add_something {
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp"; die $@ if $@ ;
return $foo;
}
Now an injection of $MyFoo::foo = -17 won't be possible.
package MyFoo;
our( $foo, $tmp );
sub add_something {
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp";
return $foo;
}
package SatanicLaughter;
use overload
'+' => sub {
my $self = $_[0];
print STDERR ("I'm the lord of inverse and bring you subtraction!\n");
return $$self -= $_[1];
};
sub new
{
my $self;
$self = $_[1];
return bless(\$self, $_[0]);
}
package FoosRUs;
print MyFoo::add_something(14), "\n";
my $x = SatanicLaughter->new($MyFoo::foo);
*MyFoo::foo = \$x;
print MyFoo::add_something(15), "\n";
C.DeRykus said:....
use Scalar::Util qw(blessed);
package MyFoo;
our( $foo, $tmp );
sub add_something {
my $class = Scalar::Util::blessed( $foo );
die <<END if $class;
Regretfully, the church had to perform an unscheduled exorcism of a potentially satanic blessing. This church must insist all supplicants enter unblessed at this time. Thank you for your understanding and good will."
END
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp";
return $foo;
}
....
package FoosRUs;
print MyFoo::add_something(14), "\n";
my $x = SatanicLaughter->new($MyFoo::foo);
*MyFoo::foo = \$x;
my $blessed = \&Scalar::Util::blessed;
*Scalar::Util::blessed = sub($) {
if (caller() eq 'MyFoo') {
print STDERR <<TT;
The economy has been turned around in your area and the
IT system of the contractor who pockets the money for
providing what used to be this service doesn't (yet)
work as you might have come to expect.
Because this doesn't cost us anything, we apologize for
any inconvenience caused.
TT
return;
&$blessed;
};
print MyFoo::add_something(15), "\n";
package MyFoo;
our( $foo, $tmp);
sub add_something
{
die <<END if CORE::ref($foo);
*** Dear Supplicant:
Halleujah, there's been an exorcism of
potential satanic works. However, our
sanctuary remains in a state of siege.
Please ignore any screen output with
the mark of the beast. Any suggestions
to combat this ongoing threat will be
most gratefully received.
END
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp";
return $foo;
}
Ben Morrow said:require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
or, indeed, since List::Util is a well-behaved module,
delete $INC{"List/Util.pm"};
{
no warnings "redefine";
require List::Util;
}
Ben Morrow said:require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
or, indeed, since List::Util is a well-behaved module,
delete $INC{"List/Util.pm"};
{
no warnings "redefine";
require List::Util;
}
Ben Morrow said:require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
or, indeed, since List::Util is a well-behaved module,
delete $INC{"List/Util.pm"};
{
no warnings "redefine";
require List::Util;
}
Quoth "C.DeRykus" <derykus@gmail.
...
require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
or, indeed, since List::Util is a well-behaved module,
delete $INC{"List/Util.pm"};
{
no warnings "redefine";
require List::Util;
}
Ben Morrow said:Quoth Rainer Weikusat said:[...]Ben Morrow said:Quoth "C.DeRykus" <[email protected]>:
On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
my $blessed = \&Scalar::Util::blessed;
*Scalar::Util::blessed = sub($) { [...]
require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
What purpose is List::Util supposed to have in here?
Try it and see . (Hint: Scalar::Util and List::Util are both part of
the Scalar-List-Utils CPAN distribution, which only installs one .so
file.)
Of course, for real paranoia this could be augmented with something like
use Variable::Magic qw/cast wizard/;
my $blessed = \&Scalar::Util::blessed;
cast *Scalar::Util::blessed, wizard set => sub {
*{$_[0]} = $blessed;
warn <<HOLIERTHANTHOU;
*** Warning: a devilish attempt to subvert the sanctity of the
sacrament has been detected. This attempt has been thwarted.
HOLIERTHANTHOU
};
though even that won't do you any good in the long run...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.