summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-04-16 15:04:36 +0000
committerNicholas Clark <nick@ccl4.org>2006-04-16 15:04:36 +0000
commit34113e50dc4bebd1212d8cbfbf09a86a40b7a699 (patch)
treed3146dcef80adf0f0d6549f7abfb313b0245e0b1 /t
parente655f126937737a64491ca38bb28ba229f1eb788 (diff)
downloadperl-34113e50dc4bebd1212d8cbfbf09a86a40b7a699.tar.gz
A scalar reference returned from a coderef in @INC is treated as the
initial "content" of the file. When it is exhausted input is taken from a real file handle, or a generator sub, if either exists. p4raw-id: //depot/perl@27849
Diffstat (limited to 't')
-rw-r--r--t/op/incfilter.t45
1 files changed, 36 insertions, 9 deletions
diff --git a/t/op/incfilter.t b/t/op/incfilter.t
index 97ce37afe9..0a5381e7fb 100644
--- a/t/op/incfilter.t
+++ b/t/op/incfilter.t
@@ -14,7 +14,7 @@ BEGIN {
use strict;
use Filter::Util::Call;
-plan(tests => 128);
+plan(tests => 141);
unshift @INC, sub {
no warnings 'uninitialized';
@@ -44,14 +44,17 @@ do \&generator or die;
# Check that the array dereferencing works ready for the more complex tests:
do [\&generator] or die;
-do [sub {
- my $param = $_[1];
- is (ref $param, 'ARRAY', "Got our parameter");
- $_ = shift @$param;
- return defined $_ ? 1 : 0;
- }, ["pass('Can return generators which take state');\n",
- "pass('And return multiple lines');\n",
- ]] or die;
+sub generator_with_state {
+ my $param = $_[1];
+ is (ref $param, 'ARRAY', "Got our parameter");
+ $_ = shift @$param;
+ return defined $_ ? 1 : 0;
+}
+
+do [\&generator_with_state,
+ ["pass('Can return generators which take state');\n",
+ "pass('And return multiple lines');\n",
+ ]] or die;
open $fh, "<", \'fail("File handles and filters work from \@INC");';
@@ -173,3 +176,27 @@ pass("You should see this line thrice");
EOC
do [$fh, sub {$_ .= $_ . $_; return;}] or die;
+
+do \"pass\n(\n'Scalar references are treated as initial file contents'\n)\n"
+or die;
+
+open $fh, "<", \"ss('The file is concatentated');";
+
+do [\'pa', $fh] or die;
+
+open $fh, "<", \"ff('Gur svygre vf bayl eha ba gur svyr');";
+
+do [\'pa', $fh, sub {tr/A-Za-z/N-ZA-Mn-za-m/; return;}] or die;
+
+open $fh, "<", \"SS('State also works');";
+
+do [\'pa', $fh, sub {s/($_[1])/lc $1/ge; return;}, "S"] or die;
+
+@lines = ('ss', '(', "'you can use a generator'", ')');
+
+do [\'pa', \&generator] or die;
+
+do [\'pa', \&generator_with_state,
+ ["ss('And generators which take state');\n",
+ "pass('And return multiple lines');\n",
+ ]] or die;