Inline-Files-0.71/0000755000175000017500000000000013450135363012350 5ustar ambsambsInline-Files-0.71/MANIFEST0000755000175000017500000000130013450135363013476 0ustar ambsambsChanges MANIFEST Makefile.PL README demo/XML.xml demo/demo_XML demo/demo_multiple.pl demo/demo_persistence.pl demo/demo_persistence_simple.pl demo/demo_simple.pl demo/demo_singles.pl demo/demo_virtual.pl demo/demo_nowrite.pl demo/demo_write.pl lib/Inline/Files.pm lib/Inline/Files/Virtual.pm t/00init.t t/01basics.t t/02write.t t/03nowrite.t t/04create.t t/05seek.t t/06backup.t t/07hash.t tests/01basics.t tests/02write.t tests/03nowrite.t tests/04create.t tests/05seek.t tests/06backup.t tests/07hash.t t/08coreopen.t t/testrules.yml META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Inline-Files-0.71/tests/0000755000175000017500000000000013450135363013512 5ustar ambsambsInline-Files-0.71/tests/03nowrite.t0000755000175000017500000000117612530325063015535 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } { local $^W; open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; } { local $/; open FILE, $0; my $text = ; close FILE; skip( $> == 0 ? "Skip if run by superuser" : ($^O eq 'cygwin' ? "Skip if under cygwin" : 0), $text !~ /__MYFILE__\nNew stuff\n$/ ); } __MYFILE__ Old stuff Inline-Files-0.71/tests/06backup.t0000755000175000017500000000136711605557053015330 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 4, todo => [], onfail => sub {}, ); } use Inline::Files -backup; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } { local $/; open FILE, "$0.bak"; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nNew stuff\n$/); } { local $/; open FILE, "$0.bak"; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } unlink "$0.bak"; __MYFILE__ Old stuff Inline-Files-0.71/tests/07hash.t0000755000175000017500000000124311605560144014773 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test::More; BEGIN { plan(tests => 12, todo => [], onfail => sub {}, ); } use Inline::Files; use vars '%MYFILE'; { local $/; ok(!defined $MYFILE{file}); ok(!defined $MYFILE{line}); ok(!defined $MYFILE{offset}); ok($MYFILE{writable}); ok(!defined $MYFILE{other}); open MYFILE; like($MYFILE{file} => qr/07hash.t$/); is($MYFILE{line} => 34); is($MYFILE{offset} => 654); ok($MYFILE{writable}); ok(!eval{ $MYFILE{writable}=0; 1 }); ok(!defined $MYFILE{other}); my $text = ; close MYFILE; like($text => qr/Old stuff\n$/); } __MYFILE__ Old stuff Inline-Files-0.71/tests/01basics.t0000755000175000017500000000070611605557042015314 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; BEGIN { $| = 1; print "1..9\n"; } use Inline::Files; my $loaded = 1; END {print "not ok 1\n" unless $loaded;} print "ok 1\n"; print while ; open SECOND_VIRTUAL and do { print for ; 1 } or print "not ok 8\n"; __VIRTUAL__ ok 2 ok 3 ok 4 __SECOND_VIRTUAL__ ok 8 ok 9 __VIRTUAL__ ok 5 ok 6 __OTHER__ not ok 666 __VIRTUAL__ __VIRTUAL__ ok 7 __SECOND_VIRTUAL__ not ok 10 not ok 11 Inline-Files-0.71/tests/04create.t0000755000175000017500000000127211605557050015314 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text !~ /^__MYFILE1__$/m and $text !~ /^__MYFILE2__$/m ); } { local $^W; open MYFILE1, '>' or die "$!"; open MYFILE2, '>' or die "$!"; print MYFILE1 ("one\n"); print MYFILE2 ("two\n"); print MYFILE1 ("three\n"); # print MYXFILE ("four\n"); close \*MYFILE1; close \*MYFILE2; } { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE1__\none\nthree\n__MYFILE2__\ntwo\n$/); } Inline-Files-0.71/tests/05seek.t0000755000175000017500000000163011605557051015000 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 21, todo => [], onfail => sub {}, ); } use Inline::Files; #1 ok( =~ /This is line 1/); #2 ok(not seek IFILE, -10, 0); #3 ok(seek IFILE, -10, 1); #4 ok( =~ /line 1/); #5 ok(seek IFILE, 20, 1); #6 ok( =~ /line 3/); #7 ok(seek IFILE, 500, 0); #8 ok(not seek IFILE, -500, 1); #9 ok(seek IFILE, -30, 1); #10 ok( =~ /line 4/); #11 ok(not seek IFILE, -500, 2); #12 ok(seek IFILE, -30, 2); #13 ok( =~ /line 4/); #14 ok(seek IFILE, -30, 1); #15 ok( =~ /line 3/); #16 ok(seek IFILE, 0, 0); #17 ok( =~ /line 1/); #18 ok(seek IFILE, 16, 1); #19 ok( =~ /line 3/); #20 eval "seek IFILE, 16, 1, 0"; ok($@ =~ /Too many arguments for/); #21 eval "seek IFILE, 16"; ok($@ =~ /Not enough arguments for/); __IFILE__ This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 Inline-Files-0.71/tests/02write.t0000755000175000017500000000073511605557044015207 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nNew stuff\n$/); } __MYFILE__ Old stuff Inline-Files-0.71/META.yml0000644000175000017500000000121513450135363013620 0ustar ambsambs--- abstract: 'Multiple virtual files at the end of your code' author: - unknown build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Inline-Files no_index: directory: - t - inc requires: Cwd: '0' Filter::Util::Call: '0' Test: '0' resources: repository: https://gitlab.com/ambs/perl5-inline-files.git version: '0.71' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Inline-Files-0.71/t/0000755000175000017500000000000013450135363012613 5ustar ambsambsInline-Files-0.71/t/03nowrite.t0000444000175000017500000000117613450135361014633 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } { local $^W; open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; } { local $/; open FILE, $0; my $text = ; close FILE; skip( $> == 0 ? "Skip if run by superuser" : ($^O eq 'cygwin' ? "Skip if under cygwin" : 0), $text !~ /__MYFILE__\nNew stuff\n$/ ); } __MYFILE__ Old stuff Inline-Files-0.71/t/06backup.t0000644000175000017500000000137013450135361014412 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 4, todo => [], onfail => sub {}, ); } use Inline::Files -backup; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } { local $/; open FILE, "$0.bak"; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nNew stuff\n$/); } { local $/; open FILE, "$0.bak"; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } unlink "$0.bak"; __MYFILE__ New stuff Inline-Files-0.71/t/testrules.yml0000644000175000017500000000045413450102473015367 0ustar ambsambs# TAP::Harness test rules # "t\00init.t" should *not* be run in parallel # ... parallel execution causes file system race conditions and multiple failures seq: - seq: # serialize all tests in files matching "t/0*.t" - t{\\,/}00init.t - par: # run all other tests in parallel - ** Inline-Files-0.71/t/07hash.t0000644000175000017500000000124313450135361014070 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test::More; BEGIN { plan(tests => 12, todo => [], onfail => sub {}, ); } use Inline::Files; use vars '%MYFILE'; { local $/; ok(!defined $MYFILE{file}); ok(!defined $MYFILE{line}); ok(!defined $MYFILE{offset}); ok($MYFILE{writable}); ok(!defined $MYFILE{other}); open MYFILE; like($MYFILE{file} => qr/07hash.t$/); is($MYFILE{line} => 34); is($MYFILE{offset} => 654); ok($MYFILE{writable}); ok(!eval{ $MYFILE{writable}=0; 1 }); ok(!defined $MYFILE{other}); my $text = ; close MYFILE; like($text => qr/Old stuff\n$/); } __MYFILE__ Old stuff Inline-Files-0.71/t/08coreopen.t0000644000175000017500000000202711605557110014761 0ustar ambsambs# -*- cperl -*- use lib qw(./blib/lib ../blib/lib); use strict; BEGIN { $| = 1; print "1..12\n"; } use Inline::Files; # 1..2 open X, ">out.tmp" or die; print X "ok 2\n"; close X; print "ok 1\n" if -f "out.tmp"; open Y, "out.tmp" or die; print ; close Y; unlink "out.tmp"; # 3..4 open X, ">", "out.tmp" or die; print X "ok 4\n"; close X; print "ok 3\n" if -f "out.tmp"; open Y, "<", "out.tmp" or die; print ; close Y; unlink "out.tmp"; # 5..7 open X, ">out.tmp" or die; print X "ok 6\n"; close X; print "ok 5\n" if -f "out.tmp"; open X, ">>out.tmp" or die; print X "ok 7\n"; close X; open Y, "out.tmp" or die; print ; close Y; unlink "out.tmp"; # 8..10 open X, ">","out.tmp" or die; print X "ok 9\n"; close X; print "ok 8\n" if -f "out.tmp"; open X, ">>","out.tmp" or die; print X "ok 10\n"; close X; open Y, "; close Y; unlink "out.tmp"; # 11..12 open X, qq{$^X -e "print 'ok 11'" | } or die "$!"; print , "\n"; close X; open X, "-|", qq{$^X -e "print 'ok 12'" } or die "$!"; print , "\n"; close X; Inline-Files-0.71/t/01basics.t0000644000175000017500000000070613450135361014406 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; BEGIN { $| = 1; print "1..9\n"; } use Inline::Files; my $loaded = 1; END {print "not ok 1\n" unless $loaded;} print "ok 1\n"; print while ; open SECOND_VIRTUAL and do { print for ; 1 } or print "not ok 8\n"; __VIRTUAL__ ok 2 ok 3 ok 4 __SECOND_VIRTUAL__ ok 8 ok 9 __VIRTUAL__ ok 5 ok 6 __OTHER__ not ok 666 __VIRTUAL__ __VIRTUAL__ ok 7 __SECOND_VIRTUAL__ not ok 10 not ok 11 Inline-Files-0.71/t/04create.t0000644000175000017500000000134013450135361014403 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text !~ /^__MYFILE1__$/m and $text !~ /^__MYFILE2__$/m ); } { local $^W; open MYFILE1, '>' or die "$!"; open MYFILE2, '>' or die "$!"; print MYFILE1 ("one\n"); print MYFILE2 ("two\n"); print MYFILE1 ("three\n"); # print MYXFILE ("four\n"); close \*MYFILE1; close \*MYFILE2; } { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE1__\none\nthree\n__MYFILE2__\ntwo\n$/); } __MYFILE1__ one three __MYFILE2__ two Inline-Files-0.71/t/05seek.t0000644000175000017500000000163013450135361014072 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 21, todo => [], onfail => sub {}, ); } use Inline::Files; #1 ok( =~ /This is line 1/); #2 ok(not seek IFILE, -10, 0); #3 ok(seek IFILE, -10, 1); #4 ok( =~ /line 1/); #5 ok(seek IFILE, 20, 1); #6 ok( =~ /line 3/); #7 ok(seek IFILE, 500, 0); #8 ok(not seek IFILE, -500, 1); #9 ok(seek IFILE, -30, 1); #10 ok( =~ /line 4/); #11 ok(not seek IFILE, -500, 2); #12 ok(seek IFILE, -30, 2); #13 ok( =~ /line 4/); #14 ok(seek IFILE, -30, 1); #15 ok( =~ /line 3/); #16 ok(seek IFILE, 0, 0); #17 ok( =~ /line 1/); #18 ok(seek IFILE, 16, 1); #19 ok( =~ /line 3/); #20 eval "seek IFILE, 16, 1, 0"; ok($@ =~ /Too many arguments for/); #21 eval "seek IFILE, 16"; ok($@ =~ /Not enough arguments for/); __IFILE__ This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 Inline-Files-0.71/t/02write.t0000644000175000017500000000073613450135361014300 0ustar ambsambsuse lib qw(./blib/lib ../blib/lib); use strict; use Test; BEGIN { plan(tests => 2, todo => [], onfail => sub {}, ); } use Inline::Files; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nOld stuff\n$/); } open MYFILE, '>'; print MYFILE "New stuff\n"; close \*MYFILE; { local $/; open FILE, $0; my $text = ; close FILE; ok($text =~ /__MYFILE__\nNew stuff\n$/); } __MYFILE__ New stuff Inline-Files-0.71/t/00init.t0000755000175000017500000000046611605557062014120 0ustar ambsambsuse strict; use Test; use File::Copy; plan(tests => 15); my $orig = './tests/'; my $local = './t/'; foreach (qw( 01basics 02write 03nowrite 04create 05seek 06backup 07hash )) { ok(unlink("$local$_.t") or not -f "$local$_.t"); ok(copy("$orig$_.t", "$local$_.t")); } ok(chmod 0444, "$local/03nowrite.t"); Inline-Files-0.71/lib/0000755000175000017500000000000013450135363013116 5ustar ambsambsInline-Files-0.71/lib/Inline/0000755000175000017500000000000013450135363014334 5ustar ambsambsInline-Files-0.71/lib/Inline/Files.pm0000755000175000017500000002450013450135347015742 0ustar ambsambspackage Inline::Files; $VERSION = '0.71'; use strict; use Inline::Files::Virtual; use Filter::Util::Call; use Cwd qw(abs_path); use Carp; my $SOVFM_pat = qr/^__[A-Z](?:_*[A-Z0-9]+)*__\n/m; my %files; sub import { DEBUG && TRACE(@_); my ($class, @args) = @_; my ($package, $file, $line) = caller; my $path = './'; $file =~ s|\\|/|g; ($path, $file) = ($1, $2) if $file =~ m|^(.*)/(.*)$|; $file = abs_path($path) . "/$file"; $files{$package} = $file; while (@args) { my $next = shift @args; if ($next eq '-backup') { my $backup = shift(@args)||"$file.bak"; local (*IN, *OUT); open IN, $file and open OUT, ">$backup" and print OUT and close IN and close OUT or croak "Cannot make backup of '$file'\n($!)"; } else { croak "usage: use $class [-backup [=> 'filename']]" } } my (%symbols, $source); foreach my $vfile (vf_load($file, $SOVFM_pat)) { my $symbol = vf_marker($vfile); $symbol =~ s/^__|__\n//g; push @{$symbols{$symbol}}, $vfile; } foreach my $symbol (keys %symbols) { no strict 'refs'; my $fq_symbol = "${package}::${symbol}"; @$fq_symbol = @{$symbols{$symbol}}; $$fq_symbol = $symbols{$symbol}[0]; my $impl = tie *$fq_symbol, $class, $fq_symbol, -w $file; tie %$fq_symbol, $class."::Data", $impl; } foreach (qw( open close seek tell truncate write )) { no strict 'refs'; *{"CORE::GLOBAL::$_"} = \&{"vf_$_"}; } ($source = vf_prefix($file)) =~ s/(.*\n){$line}//; filter_add( sub { return 0 unless $source; $_ = $source; $source = ""; return 1; } ); } sub TIEHANDLE { DEBUG && TRACE(@_); my ($class, $symbol, $writable) = @_; bless { symbol => $symbol, writable => $writable }, $class; } sub STORE { DEBUG && TRACE(@_); } sub DESTROY { DEBUG && TRACE(@_); } sub AUTOLOAD { DEBUG && TRACE(@_) && print "AUTOLOAD => $Inline::Files::AUTOLOAD\n"; no strict; local $^W; my $impl = shift; my $symbol = $impl->{symbol}; untie *$symbol; $$symbol = shift @$symbol; return unless $$symbol; my $open_mode = $impl->{writable} ? "+<" : "<"; vf_open $symbol, "$open_mode$$symbol", $symbol or return; croak "Internal error" unless tied *$symbol; $AUTOLOAD =~ s/.*:://; local $Carp::CarpLevel = 1; return tied(*$symbol)->$AUTOLOAD(@_); } sub get_filename { DEBUG && TRACE(@_); $files{$_[0]} || ""; } package Inline::Files::Data; use Carp; BEGIN { *DEBUG = \&Inline::Files::DEBUG; *TRACE = \&Inline::Files::TRACE; } sub access { DEBUG && TRACE(@_); no strict 'refs'; tied(*{$_[0]->{impl}{symbol}}); } my %fetch = ( file => sub { access($_[0])->{afile} }, line => sub { access($_[0])->{vfile}{line}}, offset => sub { access($_[0])->{vfile}{offset}}, writable => sub { $_[0]->{impl}{writable} }, ); my @validkeys = keys %fetch; my $validkey = qr/${\join '|', @validkeys}/; sub TIEHASH { DEBUG && TRACE(@_); my ($class, $impl) = @_; bless { impl=>$impl, iter=>0 }, $class; } sub FETCH { DEBUG && TRACE(@_); my ($self, $key) = @_; return undef unless $key =~ $validkey; return $fetch{$key}->($self); } sub FIRSTKEY { DEBUG && TRACE(@_); return $validkeys[$_[0]->{iter} = 0]; } sub NEXTKEY { DEBUG && TRACE(@_); return $validkeys[++$_[0]->{iter}]; } sub EXISTS { DEBUG && TRACE(@_); return $_[1] =~ $validkey; } sub DESTROY { DEBUG && TRACE(@_); } sub AUTOLOAD { DEBUG && TRACE(@_); croak "Cannot modify read-only hash"; } 1; __END__ =head1 NAME Inline::Files - Multiple virtual files at the end of your code =head1 VERSION This document describes version 0.69 of Inline::Files, released June 24, 2015. =head1 SYNOPSIS use Inline::Files; my Code $here; # etc. # etc. # etc. __FOO__ This is a virtual file at the end of the data __BAR__ This is another virtual file __FOO__ This is yet another such file =head1 WARNING It is possible that this module may overwrite the source code in files that use it. To protect yourself against this possibility, you are I advised to use the C<-backup> option described in L<"Safety first">. This module is still experimental. Regardless of whether you use C<-backup> or not, by using this module you agree that the authors will b be responsible for any loss of data, code, time, money, or limbs, or for any other disadvantage incurred as a result of using Inline::Files. =head1 DESCRIPTION Inline::Files generalizes the notion of the C<__DATA__> marker and the associated CDATAE> filehandle, to an arbitrary number of markers and associated filehandles. When you add the line: use Inline::Files; to a source file you can then specify an arbitrary number of distinct virtual files at the end of the code. Each such virtual file is marked by a line of the form: __SOME_SYMBOL_NAME_IN_UPPER_CASE__ The following text -- up to the next such marker -- is treated as a file, whose (pseudo-)name is available as an element of the package array C<@SOME_SYMBOL_NAME_IN_UPPER_CASE>. The name of the first virtual file with this marker is also available as the package scalar C<$SOME_SYMBOL_NAME_IN_UPPER_CASE>. The filehandle of the same name is magical -- just like C -- in that it automatically opens itself when first read. Furthermore -- just like C -- the filehandle re-opens itself to the next appropriate virtual file (by C-ing the first element of C<@SOME_SYMBOL_NAME_IN_UPPER_CASE> into C<$SOME_SYMBOL_NAME_IN_UPPER_CASE>) whenever it reaches EOF. So, just as with C, you can treat all the virtual files associated with a single symbol either as a single, multi-part file: use Inline::Files; while () { print "$FILE: $_"; } __FILE__ File 1 here __FILE__ File 2 here __OTHER_FILE__ Other file 1 __FILE__ File 3 here or as a series of individual files: use Inline::Files; foreach $filename (@FILE) { open HANDLE, $filename; print "<<$filename>>\n"; while () { print; } } __FILE__ File 1 here __FILE__ File 2 here __OTHER_FILE__ Other file 1 __FILE__ File 3 here Note that these two examples completely ignore the lines: __OTHER_FILE__ Other file 1 which would be accessed via the C filehandle. Unlike CARGVE>/C<@ARGV>/C<$ARGV>, Inline::Files also makes use of the hash associated with an inline file's symbol. That is, when you create an inline file with a marker C<__WHATEVER__>, the hash C<%WHATEVER> will contain information about that file. That information is: =over =item C<$WHATEVER{file}> The name of the disk file in which the inlined C<__WHATEVER__> files were defined; =item C<$WHATEVER{line}> The line (starting from 1) at which the current inline C<__WHATEVER__> file being accessed by CWHATEVERE> started. =item C<$WHATEVER{offset}> The byte offset (starting from 0) at which the current inline C<__WHATEVER__> file being accessed by CWHATEVERE> started. =item C<$WHATEVER{writable}> Whether the the current inline file being accessed by CWHATEVERE> is opened for output. =back The hash and its elements are read-only and the entry values are only meaningful when the corresponding filehandle is open. =head2 Writable virtual files If the source file that uses Inline::Files is itself writable, then the virtual files it contains may also be opened for write access. For example, here is a very simple persistence mechanism: use Inline::Files; use Data::Dumper; open CACHE or die $!; # read access (uses $CACHE to locate file) eval join "", ; close CACHE or die $!; print "\$var was '$var'\n"; while (<>) { chomp; $var = $_; print "\$var now '$var'\n"; } open CACHE, ">$CACHE" or die $!; # write access print CACHE Data::Dumper->Dump([$var],['var']); close CACHE or die $!; __CACHE__ $var = 'Original value'; I C, if a virtual file is part of a writable file and is automagically opened, it is opened for full read/write access. So the above example, could be even simpler: use Inline::Files; use Data::Dumper; eval join "", ; # Automagically opened print "\$var was '$var'\n"; while (<>) { chomp; $var = $_; print "\$var now '$var'\n"; } seek CACHE, 0, 0; print CACHE Data::Dumper->Dump([$var],['var']); __CACHE__ $var = 'Original value'; In either case, the original file is updated only at the end of execution, on an explicit C of the virtual file's handle, or when C is explicitly called. =head2 Creating new Inline files on the fly. You can also open up new Inline output files at run time. Simply use the open function with a valid new Inline file handle name and B file name. Like this: use Inline::Files; open IFILE, '>'; print IFILE "This line will be placed into a new Inline file\n"; print IFILE "which is marked by '__IFILE__'\n"; =head2 Safety first Because Inline::Files handles are often read-write, it's possible to accidentally nuke your hard-won data. But Inline::Files can save you from yourself. If Inline::Files is loaded with the C<-backup> option: use Inline::Files -backup; then the source file that uses it is backed up before the inline files are extracted. The backup file is the name of the source file with the suffix ".bak" appended. You can also specify a different name for the backup file, by associating that name with the C<-backup> flag: use Inline::Files -backup => '/tmp/sauve_qui_peut'; =head1 SEE ALSO The Inline::Files::Virtual module The Filter::Util::Call module =head2 BUGS ADDED BY Alberto Simoes (ambs@cpan.org) =head1 UNWITTING PAWN OF AN AUTHOR Damian Conway (damian@conway.org) =head1 EVIL MASTERMIND BEHIND IT ALL Brian Ingerson (INGY@cpan.org) =head1 COPYRIGHT Copyright (c) 2001-2009. Damian Conway. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html =cut Inline-Files-0.71/lib/Inline/Files/0000755000175000017500000000000013450135363015376 5ustar ambsambsInline-Files-0.71/lib/Inline/Files/Virtual.pm0000755000175000017500000004476213450103450017372 0ustar ambsambspackage Inline::Files::Virtual; $VERSION = '0.70'; use strict; use Carp; use Cwd qw(abs_path); # To Do: # - Add an EOF flag and make sure (virtual) system calls treat it right # - Call close on an implicit open. # - Add unlink(). Should behave properly if file is open. # - Support this idiom for multiple FOO: # open FOO; # close FOO; # while (open FOO) { # while () { # } # } # Damian. Let's leave this trace feature in for a while. # The calls to it should be constant folded out of the bytecode anyway, # (when DEBUG is 0) so there's no real performance penalty. # It has helped me find many a bug :) BEGIN { sub DEBUG () { 0 } my ($TRACING, $ARGS) = (1, 1); sub TRACING {$ENV{INLINE_FILES_TRACE} || $TRACING} sub ARGS {$ENV{INLINE_FILES_ARGS} || $ARGS} sub TRACE { $| = 1; local $^W; return unless TRACING || ARGS; print "=" x 79, "\n" if ARGS; print ((caller(1))[3], "\n") if TRACING || ARGS; return unless @_; require Data::Dumper; $Data::Dumper::Purity = 1; $Data::Dumper::Indent = 1; print Data::Dumper::Dumper(\@_) if ARGS; } } my %vfs; # virtual file system my %mfs; # marker-to-virtual-file mapping my %afs; # actual file system my (%read, %write, %append, %preserve); @read{qw( < +> +< )} = (); @write{qw( > +> +< >> )} = (); @append{qw( >> )} = (); @preserve{qw( >> +< < )} = (); sub not_input { "Virtual file not open for input\n" } sub not_output { "Virtual file not open for output\n" } sub import { DEBUG && TRACE(@_); my $caller = caller; no strict 'refs'; *{"${caller}::$_"} = \&$_ for (qw( vf_load vf_save vf_marker vf_prefix vf_open vf_close vf_seek vf_tell vf_truncate vf_write DEBUG TRACE )); 1; } sub vf_load { DEBUG && TRACE(@_); my ($file, $header) = @_; my $path = './'; $file =~ s|\\|/|g; ($path, $file) = ($1, $2) if $file =~ m|^(.*)/(.*)$|; $file = abs_path($path) . "/$file"; return @{$afs{$file}{vfiles}} if $afs{$file}; local ($/, *FILE); open FILE, $file or croak "Could not vf_load '$file'"; my @vdata = split /(?m)($header)/, ; my ($offset,$linecount) = (0,1); unshift @vdata, ""; my ($marker, $data, $vfiles); while (($marker, $data) = splice @vdata,0,2) { my $vfile = sprintf "$file(%-0.20d)",$offset; $vfs{$vfile} = { data => $data, marker => $marker, offset => $offset, line => $linecount, }; $offset += length($marker) + length($data); $linecount += linecount($marker, $data); push @$vfiles, $vfile; push @{$mfs{$marker}}, $vfile; } $afs{$file}{vfiles} = $vfiles; return @{$vfiles}[1..$#$vfiles]; } my $new_counter = 0; sub vf_open (*;$$$) { DEBUG && TRACE(@_); my $glob = shift; my $file = shift; my $symbol = shift; my $mode; if ($file && $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/) { $mode = $file; $file = $symbol; $symbol = shift; } no strict; if (defined $glob) { $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; # The following line somehow manages to cause failure on threaded perls. # The good news is that everything works just fine without it. # $glob = \*{$glob}; } else { # autovivify for: open $fh, $filename $glob = $_[0] = \do{local *ANON}; } if (!$mode) { # Resolve file $file ||= ""; $file =~ s/^([^\w\s\/]*)\s*//i; $mode = $1 || ""; if (!$mode && $file =~ s/\s*\|\s*$//) { $mode = $mode || "-|"; } } unless ($file) { my $scalar = *{$glob}{SCALAR}; $file = $scalar ? $$scalar : ""; $file =~ s/^([^a-z\s\/]*)\s*//i; $mode = $mode || $1 || "<"; } $mode ||= "<"; $file = $mfs{$file}[0] if $file and exists $mfs{$file}; # Create a new Inline file (for Inline::Files only) if (not $file and defined $Inline::Files::{get_filename}) { (my $marker = *{$glob}{NAME}) =~ s|.*::(.*)|$1|; if ($marker =~ /^[A-Z](?:_*[A-Z0-9]+)*$/) { if ($file = Inline::Files::get_filename((caller)[0])) { $marker = "__${marker}__\n"; my $vfile = sprintf "$file(NEW%-0.8d)", ++$new_counter; $vfs{$vfile} = { data => '', marker => $marker, offset => -1, line => -1, }; push @{$mfs{$marker}}, $vfile; push @{$afs{$file}{vfiles}}, $vfile; $file = $vfile; } } } $! = 2, return 0 unless $file; # Can't work at this point; confuses core # Default to CORE::open unless (exists $vfs{$file}) { return CORE::open($glob, $mode, $file); } my $afile = $file =~ /^(.*)[(](NEW)?\d+[)]$/ ? $1 : croak "Internal error\n"; # If file is virtual, tie it up, and set it up my $impl = tie (*$glob, 'Inline::Files::Virtual', $file, $afile, $mode, $symbol); $afs{$afile}{changed} = 0; $impl->TRUNCATE() if (exists $write{$mode} and not exists $preserve{$mode}); return 1; } sub linecount { DEBUG && TRACE(); my $sum = 0; foreach (@_) { $sum += tr/\n// } return $sum; } sub vf_save { DEBUG && TRACE(@_); my @files = @_; @files = keys %afs unless @files; for my $file (@files) { next unless $afs{$file}{changed}; $afs{$file}{changed}=0; local *FILE; open FILE, ">$file" and print FILE map { my $entry = $vfs{$_}; if (length $entry->{data}) { chomp $entry->{data}; $entry->{data} .= "\n"; } "$entry->{marker}$entry->{data}"; } @{$afs{$file}{vfiles}} and close FILE or ($^W and warn "Could not vf_save '$file'\n$!") and return 0; } return 1; } END { DEBUG && TRACE(@_); vf_save; } sub vf_marker ($) { DEBUG && TRACE(@_); my ($virtual_filename) = @_; return $vfs{$virtual_filename}{marker}; } sub vf_prefix ($) { DEBUG && TRACE(@_); my ($actual_filename) = @_; return $vfs{$afs{$actual_filename}{vfiles}[0]}{data}; } sub vf_close (*) { DEBUG && TRACE(@_); my ($glob) = @_; no strict; $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; my $impl = tied(*$glob); return CORE::close $glob unless $impl; return vf_save(); } sub vf_seek (*$$) { DEBUG && TRACE(@_); my ($glob, $pos, $whence) = @_; no strict; $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; my $impl = tied(*$glob); return seek $glob, $pos, $whence unless $impl; return $impl->SEEK($pos, $whence); } sub vf_tell (*) { DEBUG && TRACE(@_); my ($glob) = @_; no strict; $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; my $impl = tied(*$glob); return tell $glob unless $impl; return $impl->TELL(); } sub vf_truncate (*$) { DEBUG && TRACE(@_); my ($glob, $length) = @_; no strict; $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; my $impl = tied(*$glob); return truncate $glob, $length unless $impl; return $impl->TRUNCATE($length); } sub vf_write (*) { DEBUG && TRACE(@_); my ($glob) = @_; no strict; $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/; my $impl = tied(*$glob); return write $glob unless $impl; return $impl->WRITE(); } sub TIEHANDLE { DEBUG && TRACE(@_); my ($class, $vfile, $afile, $mode, $symbol) = @_; my $vfs_entry = $vfs{$vfile} or return; bless { vfile => $vfs_entry, pos => exists $append{$mode} ? length $vfs_entry->{data} : 0, mode => $mode, symbol => $symbol, afile => $afile, }, $class; } sub STORE { DEBUG && TRACE(@_); } sub PRINT { DEBUG && TRACE(@_); my($impl,@args) = @_; $^W && warn(not_output), return 1 unless exists $write{$impl->{mode}}; my $text = join '', @args; substr($impl->{vfile}{data},$impl->{pos},-1) = $text; $impl->{pos} += length $text; $afs{$impl->{afile}}{changed} = 1; return 1; } sub PRINTF { DEBUG && TRACE(@_); my($impl,$format,@args) = @_; $^W && warn(not_output), return 1 unless exists $write{$impl->{mode}}; my $text = sprintf($format,@args); substr($impl->{vfile}{data},$impl->{pos},-1) = $text; $impl->{pos} += length $text; $afs{$impl->{afile}}{changed} = 1; return 1; } use vars '$AUTOLOAD'; sub AUTOLOAD { DEBUG && TRACE(@_); my $impl = shift; croak "$AUTOLOAD not yet implemented"; } sub DESTROY { DEBUG && TRACE(@_); } # Inline::Files support sub _magic_handle { DEBUG && TRACE(@_); my ($impl) = @_; return unless $INC{'Inline/Files.pm'} && $impl->{symbol}; no strict 'refs'; return tie *{$impl->{symbol}}, 'Inline::Files', $impl->{symbol}; } sub READ { DEBUG && TRACE(@_); my($impl,$buffer,$length,$offset) = @_; $^W && warn(not_input), return unless exists $read{$impl->{mode}}; $offset = $impl->{pos} unless defined $offset; my $remainder = length($impl->{vfile}{data})-$impl->{pos}; $length = $remainder if $remainder < $length; $_[1] = substr($impl->{vfile}{data},$offset,$length); $impl->{pos} += $length; if ($length>=0) { return $length } elsif ($impl = _magic_handle($impl)) { return $impl->READ($buffer,$length,$offset); } else { return; } } sub READLINE { DEBUG && TRACE(@_); my ($impl) = @_; $^W && warn(not_input), return unless exists $read{$impl->{mode}}; my $match = !defined($/) ? '.*' : length $/ ? ".*?\Q$/\E|.*" : '.*?\n{2,}'; my (@lines); my $list_context ||= wantarray; while (1) { if ($impl->{pos} < length $impl->{vfile}{data} and $impl->{vfile}{data} =~ m{\A(.{$impl->{pos}})($match)}s) { $impl->{pos} += length($2); push @lines, $2; } else { last unless $impl = _magic_handle($impl); last unless $impl = $impl->MAGIC; next; } last unless $list_context; } return $list_context ? (@lines) : @lines ? $lines[0] : undef; } sub MAGIC { DEBUG && TRACE(@_); $_[0]; } sub GETC { DEBUG && TRACE(@_); my ($impl) = @_; $^W && warn(not_input), return unless exists $read{$impl->{mode}}; my $char = substr($impl->{vfile}{data},$impl->{pos},1); $impl->{pos}++; return $char if length $char; return unless $impl = _magic_handle($impl); return $impl->GETC(); } sub TELL { DEBUG && TRACE(@_); my ($impl) = @_; return $impl->{pos}; } sub SEEK { DEBUG && TRACE(@_); my ($impl, $position, $whence) = @_; my $length = length $impl->{vfile}{data}; my $pos = $impl->{pos}; $pos = ( $whence==0 ? $position : $whence==1 ? $position + $impl->{pos} : $whence==2 ? $position + $length : return ); return if $pos < 0; $pos = $length if $pos >= $length; $impl->{pos} = $pos; return 1; } sub TRUNCATE { DEBUG && TRACE(@_); my ($impl, $length) = @_; $length ||= 0; substr($impl->{vfile}{data},$length,-1) = ""; $impl->{pos} = $length if $length < $impl->{pos}; $afs{$impl->{afile}}{changed} = 1; return 1; } 1; __END__ =head1 NAME Inline::Files::Virtual - Multiple virtual files in a single file =head1 VERSION This document describes version 0.53 of Inline::Files::Virtual, released May 25, 2001. =head1 SYNOPSIS use Inline::Files::Virtual; # Load actual file, extracting virtual files that start with "^\n" @virtual_filenames = vf_load($actual_file, "^\n"); # Open one of the virtual files for reading open(FILE, $virtual_filenames[0]) or die; print while ; close(FILE); # Open one of the virtual files for appending open(FILE, ">> $virtual_filenames[1]") or die; print FILE "extra text"; printf FILE "%6.2", $number; close(FILE); # Actual file will be updated at this point =head1 WARNING This module is still experimental. Careless use of it will almost certainly cause the source code in files that use it to be overwritten. You are I advised to use the Inline::Files module instead. If you chose to use this module anyway, you thereby agree that the authors will b be responsible for any loss of data, code, time, money, or limbs, or for any other disadvantage incurred as a result of using Inline::Files. =head1 DESCRIPTION This module allows you to treat a single disk file as a collection of virtual files, which may then be individually opened for reading or writing. Virtual files which have been modified are written back to their actual disk at the end of the program's execution (or earlier if the C subroutine is explicitly called). Each such virtual file is introduced by a start-of-virtual-file marker (SOVFM). This may be any sequence (or pattern) of characters that marks the beginning of the content of a virtual file. For example, the string C<"--"> might be used: -- Contents of virtual file number 1 -- Contents of virtual file number 2 -- Contents of virtual file number 3 or the pattern C: ##### VF1 ##### Contents of virtual file number 1 ##### VF2 ##### Contents of virtual file number 2 ##### VF3 ##### Contents of virtual file number 3 Note that the SOVFM is not considered to be part of the file contents. =head2 Interface The module exports the following methods: =over 4 =item C This subroutine is called to load an actual disk file containing one or more virtual files. The first argument specifies the name of the file to be loaded as a string. The second argument specifies a pattern (as either a string or C regex) that matches each start-of-virtual-file marker within the file. For example, if the file C contains: =info names Damian Nathan Mephistopheles =info numbers 555-1212 555-6874 555-3452 =info comment Mad Bad Dangerous to know then you could load it as three virtual files with: @virtual_filenames = vf_load("/usr/local/details.dat", qr/^=info\s+\S+\s*?\n/); Note that, because the actual file is decomposed into virtual files using a C, it is vital that the pattern does not contain any capturing parentheses. On success, C returns a list of I for the virtual files. Each virtual filename consists of the actual name of the file containing the virtual file, concatenated with the offset of the virtual file's SOVFM within the actual file. For example, the above call to C would return three virtual filenames: /usr/local/details.dat(00000000000000000000) /usr/local/details.dat(00000000000000000048) /usr/local/details.dat(00000000000000000097) When any of these virtual filenames is subsequently used in an C, the corresponding virtual file is opened. =item C =item C This subroutine causes the virtual files belonging to the nominated actual file (or files) to be written back to disk. If C is called without arguments, then I currently loaded virtual files are saved to their respective actual files at that point. C is automatically called in an C block at the termination of any program using the module. =item C This subroutine returns the SOVFM that preceded the nominated virtual file. =back The module also modifies the C, C, C, C, C, C, C, C, C, and C built-in functions so that they operate correctly on virtual files. As a special case, it is also possible to use the raw SOVFM as a virtual file name: use Inline::Files::Virtual; vf_load $filename, qr/__[A-Z]+__/; open FILE, "__MARKER__"; # and in the file that was vf_load-ed __MARKER__ file contents here However, this always opens the very first virtual file with that SOVFM, no matter how often it is called, or how many such markers appear in the file. =head2 Handling "implicit" virtual start-of-virtual-file markers Sometimes an SOVFM is "implicit". That is, rather thanb being a separate marker for the start of a virtual file, it is the first part of the actual data of the virtual file. For example, consider the following XML file: This is data set 1 datum 1 datum 2 datum 3 This is data set 2 datum 4 datum 5 datum 6 Each of the CDATAE...E/DATAE> blocks could be treated as a separate virtual file by specifying: @datasets = vf_load("data.xml", ''); But this would cause the individual virtual files to contain invalid XML, such as: This is data set 1 datum 1 datum 2 datum 3 One can indicate that the nominated SOVFMs are also part of the virtual files' contents, by specifying the markers as a look-ahead pattern: @datasets = vf_load("data.xml", '(?=)'); This causes C to identify the sequence CDATAE> as a start-of-virtual-file marker but not consume it, thereby leaving it as the initial sequence of the virtual file's content. =head1 DIAGNOSTICS =over 4 =item C The module could not open the specified disk file and read it in as a set of virtual files. =item C The module could not open the specified disk file and write it out as a set of virtual files. A preceding warning may indicate which virtual file caused the problem. =item C An attempt was made to C, C, or C a virtual file that was opened for output only. (Warning only) =item C An attempt was made to C or C a virtual file that was opened for input only. (Warning only) =back =head1 AUTHOR Damian Conway (damian@conway.org) =head1 EVIL GENIUS WHO MADE HIM DO IT Brian Ingerson (INGY@cpan.org) =head1 COPYRIGHT Copyright (c) 2001. Damian Conway. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html =cut Inline-Files-0.71/META.json0000644000175000017500000000215213450135363013771 0ustar ambsambs{ "abstract" : "Multiple virtual files at the end of your code", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Inline-Files", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Cwd" : "0", "Filter::Util::Call" : "0", "Test" : "0" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://gitlab.com/ambs/perl5-inline-files.git" } }, "version" : "0.71", "x_serialization_backend" : "JSON::PP version 4.02" } Inline-Files-0.71/Changes0000755000175000017500000000612613450135323013647 0ustar ambsambsRevision history for Perl extension Inline::Files. 0.71 Sun Mar 31 10:16:28 WEST 2019 (AMBS) - Remove weird symbol in the source. 0.70 Sun Mar 31 10:16:28 WEST 2019 (AMBS) - Added Test::Harness config file (Roy Ivy) - Added repository information on META 0.69 Sun May 24 11:39:27 WEST 2015 (AMBS) - Skip superuser test in Cygwin. 0.68 Sat Jul 23 19:45:01 WEST 2011 (AMBS) - Use 'VERSION_FROM' and 'ABSTRACT_FROM' on Makefile.PL 0.67 Fri Jul 8 12:33:03 WEST 2011 (AMBS) - Getting rid of 'diagnostics' (really!) 0.66 Thu Jul 7 12:33:03 WEST 2011 (AMBS) - Getting rid of 'diagnostics' (thanks to Sawyer X for the help) 0.65 Sat Jun 18 11:44:02 WEST 2011 (AMBS) - Require 'Test' for better debugging. 0.64 Mon Jan 31 10:53:23 WET 2011 (AMBS) - Support open with pipes (not for virtual files). Fixes #44692. 0.63 Sun May 10 17:02:02 WEST 2009 (AMBS) - Fixed test 03nowrite.t to success if run by root. - Corrected module name in the documentation 0.62 Tue May 27 23:35:53 GMT 2003 (DCONWAY) - Fixed signature of vf_truncate 0.61 Sun Jun 17 05:48:49 EST 2001 (DCONWAY) - Reinstated Ingy's workaround for desymbolization of globs under threaded perls 0.53 Thu May 24 23:51:57 PDT 2001 (INGY) - Removed doc references to diagnostics that were removed in 0.51. 0.52 Fri May 25 15:31:02 EST 2001 (DCONWAY) - Added %WHATEVER mechanism hash to access inline data about __WHATEVER__ 0.52 Fri May 25 13:50:35 EST 2001 (DCONWAY) - Silenced complaint when vf_close used on normal filehandle names 0.52 Fri May 25 13:00:53 EST 2001 (DCONWAY) - Added -backup option to import list 0.51 Mon May 21 13:40:09 PDT 2001 (INGY) - Changed seek() to work more like a real seek in regards to edge cases. (Actually set to emulate my Linux seek) 0.51 Mon May 21 13:13:39 PDT 2001 (INGY) - Warn instead of croak for user errors. More like real functions. 0.51 Mon May 21 02:08:44 PDT 2001 (INGY) - Create a new Inline File with 'open FILE ">";' 0.51 Mon May 21 02:08:44 PDT 2001 (INGY) - Make file name absolute so chdir() will not cause problems 0.51 Sun May 20 23:38:56 PDT 2001 (INGY) - Added a multi-file test harness that supports writing to files. 0.51 Sun May 20 21:51:49 PDT 2001 (INGY) - Don't croak on save() failure. Just warn if appropriate and return 0. - close() returns value of save(). 0.51 Sun May 20 21:37:07 PDT 2001 (INGY) - Set changed flag in the appropriate place - Mode got confused in some contexts 0.51 Thu Mar 22 11:29:06 PST 2001 (INGY) - Save was adding an extra newline to each written file. - NOTE: Inline::Files must always end with a newline 0.51 Thu Mar 22 11:14:11 PST 2001 (INGY) - Fixed list behaviour for PRINT 0.51 Thu Mar 22 11:04:23 PST 2001 (INGY) - Added list context for READLINE 0.51 Wed Mar 21 23:12:54 PST 2001 (INGY) - Fixed weird glob reference bug for threaded perls. 0.50 Thu Mar 15 12:00:50 2001 (DCONWAY) - First draft. Inline::Files and Inline::Files::Virtual are functional. 0.01 Fri Mar 2 06:05:33 2001 - original version; created by h2xs 1.18 0.62 Tue May 27 23:36:55 2003 Inline-Files-0.71/Makefile.PL0000755000175000017500000000110413450103305014310 0ustar ambsambs use ExtUtils::MakeMaker; WriteMakefile( NAME => q[Inline::Files], VERSION_FROM => 'lib/Inline/Files.pm', ABSTRACT_FROM => 'lib/Inline/Files.pm', PREREQ_PM => { 'Filter::Util::Call' => 0, Test => 0, Cwd => 0, }, META_MERGE => { "meta-spec" => { version => 2 }, resources => { repository => { type => 'git', url => 'git@gitlab.com:ambs/perl5-inline-files.git', web => 'https://gitlab.com/ambs/perl5-inline-files.git', }, }, }, ); Inline-Files-0.71/demo/0000755000175000017500000000000013450135363013274 5ustar ambsambsInline-Files-0.71/demo/demo_write.pl0000755000175000017500000000014007303367146015773 0ustar ambsambsuse Inline::Files; print VIRTUAL "This should work"; __VIRTUAL__ This should not be inviolate Inline-Files-0.71/demo/demo_singles.pl0000755000175000017500000000034507303367146016314 0ustar ambsambsuse Inline::Files; foreach $filename (@FILE) { open HANDLE, $filename; print "<<$filename>>\n"; while () { print; } } __FILE__ File 1 here __FILE__ File 2 here __OTHER_FILE__ other file 1 __FILE__ File 3 here Inline-Files-0.71/demo/demo_virtual.pl0000755000175000017500000000073007303367146016334 0ustar ambsambsuse Inline::Files::Virtual; my @files = vf_load($0, "^__(?:FOO|BAR)__\n"); foreach $file (@files) { local *FILE; print "<<$file>>\n"; vf_open FILE, $file or die "huh?"; while () { print "> $_"; } } print "<<<@files>>>\n"; print "<<<$files[0]>>>\n"; vf_open(FILE, "+> $files[0]"); print FILE "test"; vf_seek(FILE, 0, 0); print ; __END__ __FOO__ This is a virtual file __BAR__ This is another virtual file __FOO__ THIS IS YET ANOTHER SUCH FILE Inline-Files-0.71/demo/demo_nowrite.pl0000755000175000017500000000013707303367146016336 0ustar ambsambsuse Inline::Files; print VIRTUAL "This shouldn't work"; __VIRTUAL__ This should be inviolate Inline-Files-0.71/demo/demo_simple.pl0000755000175000017500000000063707303367146016145 0ustar ambsambsuse Inline::Files; my $here; # etc. # etc. # etc. while () { print "FOO> $_"; } my $rememBAR = $BAR; while () { print "BAR> $_"; } open BAR, "+<$rememBAR" or die $!; print BAR "Ta-da!\n"; seek BAR, 0, 0; while () { print "BAR> $_"; } print "done\n"; __FOO__ This is a virtual file at the end of the data __BAZ__ This is BAZ __BAR__ This is BAR __FOO__ This is yet another such file Inline-Files-0.71/demo/demo_multiple.pl0000755000175000017500000000023307303367146016477 0ustar ambsambsuse Inline::Files; while () { print "$FILE: $_"; } __FILE__ File 1 here __FILE__ File 2 here __OTHER_FILE__ other file 1 __FILE__ File 3 here Inline-Files-0.71/demo/demo_persistence.pl0000755000175000017500000000062007303367146017170 0ustar ambsambsuse Inline::Files; open CACHE or die $!; # read access (uses $CACHE to locate file) eval join "", ; close CACHE or die $!; print "\$var was '$var'\n"; while (<>) { chomp; $var = $_; print "\$var now '$var'\n"; } open CACHE, ">$CACHE" or die $!; # write access use Data::Dumper; print CACHE Data::Dumper->Dump([$var],['var']); close CACHE or die $!; __CACHE__ $var = 'Original value'; Inline-Files-0.71/demo/demo_persistence_simple.pl0000755000175000017500000000040207303367146020537 0ustar ambsambsuse Inline::Files; use Data::Dumper; eval join "", ; print "\$var was '$var'\n"; while (<>) { chomp; $var = $_; print "\$var now '$var'\n"; } seek CACHE, 0, 0; print CACHE Data::Dumper->Dump([$var],['var']); __CACHE__ $var = 'Original value'; Inline-Files-0.71/demo/demo_XML0000755000175000017500000000032407303367146014673 0ustar ambsambsuse Inline::Files::Virtual; my @files = vf_load("XML.xml", "(?=)"); foreach $file (@files) { local *FILE; print "<<$file>>\n"; vf_open FILE, $file or die "huh?"; while () { print "> $_"; } } Inline-Files-0.71/demo/XML.xml0000755000175000017500000000036307303367146014471 0ustar ambsambs This is an example of a marked-up file. This is another example of a marked-up file. This is yet another example of a marked-up file. This is a final example of a marked-up file. Inline-Files-0.71/README0000755000175000017500000000203213450103503013217 0ustar ambsambs============================================================================== Release of Inline::Files ============================================================================== NAME Inline::File - Multiple virtual files at the end of your code SYNOPSIS use Inline::Files; my Code $here; while () { print } # etc. __FOO__ This is a virtual file at the end of the data __BAR__ This is another virtual file __FOO__ This is yet another such file DESCRIPTION Inline::Files generalizes the notion of the `__DATA__' marker and the associated `' filehandle, to an arbitrary number of markers and associated filehandles. When you add the line: use Inline::Files; to a source file you can then specify an arbitrary number of distinct virtual files at the end of the code. AUTHOR Damian Conway (damian@conway.org) ==============================================================================