Re: Sub-refs in @INC screwing with your modules

2009-08-06 Thread David Cantrell
On Thu, Aug 06, 2009 at 09:44:24AM +0100, Aaron Crane wrote:
 Apparently open-from-a-string internally loads a module to do its magic:
   $ perl -le 'print scalar keys %INC; open my $fh, , \; print for
 keys %INC'
   0
   XSLoader.pm
   PerlIO/scalar.pm
   PerlIO.pm
 So you can make this work by doing open-from-a-string at least once
 before the @INC hook gets called:

In my case that's not necessary, because my Voodoo will return undef
for attempts to load any module it's not been told about.  Anyone trying
to use my crazy code on XSLoader or PerlIO::* deserves what they get!

http://www.cantrell.org.uk/cgit/cgit.cgi/perlmodules/tree/Sub-WrapPackages/lib/Sub/WrapPackages.pm

Incidentally, if anyone can think of a way of doing the Stuff in lines
160-171 without using a global variable, do please let me know.  The two
approaches I tried and which didn't work were:

* local $Sub::WrapPackages::params - doesn't work because it
  de-localises at the end of this subroutine, so is gone by the time it
  is needed;
* use Data::Dumper to stringify the %params, but that doesn't handle
  subrefs

-- 
David Cantrell | even more awesome than a panda-fur coat

Just because it is possible to do this sort of thing
in the English language doesn't mean it should be done


Re: Sub-refs in @INC screwing with your modules

2009-08-06 Thread Dagfinn Ilmari Mannsåker
David Cantrell da...@cantrell.org.uk writes:

 * use Data::Dumper to stringify the %params, but that doesn't handle
   subrefs

$Data::Dumper::Deparse = 1;

-- 
ilmari
A disappointingly low fraction of the human race is,
 at any given time, on fire. - Stig Sandbeck Mathisen


Re: Sub-refs in @INC screwing with your modules

2009-08-06 Thread David Cantrell
On Thu, Aug 06, 2009 at 02:49:41PM +0100, Dagfinn Ilmari Manns?ker wrote:
 David Cantrell da...@cantrell.org.uk writes:
  * use Data::Dumper to stringify the %params, but that doesn't handle
subrefs
 $Data::Dumper::Deparse = 1;

Don't think that handles closures.  Indeed, I don't see how turning your
code into text and compiling it again could ever handle them.

-- 
David Cantrell | Official London Perl Mongers Bad Influence

  NANOG makes me want to unplug everything and hide under the bed
-- brian d foy


Sub-refs in @INC screwing with your modules

2009-08-05 Thread David Cantrell
As part of an Evil Plan, I am putting a sub-ref into @INC that will
screw around with modules as they're loaded.  Or at least, I'm trying
to.  I can't seem to get this to work:

perl -MIO::Scalar -e '
unshift @INC, sub {
print q{wibble};
return IO::Scalar-new(\q{print q{wobble}})
};
eval use foo
'

which *should*, if I've RTFM correctly, print wibblewobble.  But the
wobble never appears.  What am I doing wrong?

-- 
David Cantrell | Hero of the Information Age

  Sobol's Law of Telecom Utilities:
Telcos are malicious; cablecos are simply clueless.


Re: Sub-refs in @INC screwing with your modules

2009-08-05 Thread Uri Guttman
 DC == David Cantrell da...@cantrell.org.uk writes:

  DC As part of an Evil Plan, I am putting a sub-ref into @INC that will
  DC screw around with modules as they're loaded.  Or at least, I'm trying
  DC to.  I can't seem to get this to work:

  DC perl -MIO::Scalar -e '
  DC unshift @INC, sub {
  DC print q{wibble};
  DC return IO::Scalar-new(\q{print q{wobble}})
  DC };
  DC eval use foo
  DC '

  DC which *should*, if I've RTFM correctly, print wibblewobble.  But the
  DC wobble never appears.  What am I doing wrong?

this works:

 perl -le 'open my $fh, q{}, \q{print q{bar}}; unshift @INC, sub {print 
q{foo}; $fh }; require baz'
foo
bar

i tried putting the open inside the sub and i get this error:

perl -le 'unshift @INC, sub {print q{foo}; open my $fh, q{}, \q{bar}; $fh }; 
require bar'
foo
foo
Recursive call to Perl_load_module in PerlIO_find_layer at -e line 1.
BEGIN failed--compilation aborted.

why would it recurse on the sub in @INC? it prints foo twice which shows
that.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
- Free Perl Training --- http://perlhunter.com/college.html -
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -


Re: Sub-refs in @INC screwing with your modules

2009-08-05 Thread Adriano Ferreira
On Wed, Aug 5, 2009 at 4:48 PM, David Cantrell da...@cantrell.org.ukwrote:

 As part of an Evil Plan, I am putting a sub-ref into @INC that will
 screw around with modules as they're loaded.  Or at least, I'm trying
 to.  I can't seem to get this to work:

 perl -MIO::Scalar -e '
unshift @INC, sub {
print q{wibble};
return IO::Scalar-new(\q{print q{wobble}})
};
eval use foo
 '


I don't remember the details if I tried to use IO::Scalar/IO::String to do a
similar thing in Devel::Hide and couldn't (or if I just got lazy), but the
fact is that the current Devel::Hide code uses in-memory handles (which we
got withopen(my $io, '', \$string)  for Perl 5.8+) and File::Temp for
older perls.

Best,
Adriano



 which *should*, if I've RTFM correctly, print wibblewobble.  But the
 wobble never appears.  What am I doing wrong?

 --
 David Cantrell | Hero of the Information Age

  Sobol's Law of Telecom Utilities:
Telcos are malicious; cablecos are simply clueless.