Skip Menu |

This queue is for tickets about the Module-Bundled-Files CPAN distribution.

Report information
The Basics
Id: 14869
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Module-Bundled-Files

People
Owner: kemitix [...] gmail.com
Requestors: kemitix [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.01
  • 0.02
Fixed in: 0.03



Subject: Unsafe mbf_read() behaviour inside map{}
mbf_read uses $_ internaly, and in doing so stomps on map{}s use of it. Adding a 'local $_;' into mbf_read() prevents this. Demonstration: use TestNonOO; my $o = new TestNonOO; my $data = join( "\n", map{ mbf_read( $o, $_ ) } qw{data.txt testnonoo.txt} ); Gives the error: Modification of a read-only value attempted at .../Module/Bundled/Files.pm line 266. See attached patch for fix and new test.
diff -rN old-module-bundled-files/lib/Module/Bundled/Files.pm new-module-bundled-files/lib/Module/Bundled/Files.pm 265a266 > local $_; diff -rN old-module-bundled-files/t/05-regressions.t new-module-bundled-files/t/05-regressions.t 0a1,20 > #!/usr/bin/perl -w > > # regression testing > > use Test::More tests => 2; > > { > # Bug: mbf_read was found to have problems if called within a map{} > # Problem: Use of the default variable $_ wasn't being localised > # Fix: insert a 'local $_;' into the mbf_read sub > use Module::Bundled::Files qw{mbf_read}; > # reuse the TestNonOO class as it has two files to include > use lib 't'; > use TestNonOO; > my $o = new TestNonOO; > # attempt to load and concatenate two files together > my $data = join( "\n", map{ mbf_read( $o, $_ ) }qw{data.txt testnonoo.txt} ); > like($data,qr/t-TestNonOO-data.txt/,'mbf_read data.txt'); > like($data,qr/t-TestNonOO-testnonoo.txt/,'mbf_read textnonoo.txt'); > }