Inline-Files-0.68/0000755000076500000240000000000011612613351012531 5ustar ambsstaffInline-Files-0.68/Changes0000755000076500000240000000545111612613325014035 0ustar ambsstaffRevision history for Perl extension Inline::Files. 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.68/demo/0000755000076500000240000000000011612613351013455 5ustar ambsstaffInline-Files-0.68/demo/demo_multiple.pl0000755000076500000240000000023307303367146016664 0ustar ambsstaffuse 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.68/demo/demo_nowrite.pl0000755000076500000240000000013707303367146016523 0ustar ambsstaffuse Inline::Files; print VIRTUAL "This shouldn't work"; __VIRTUAL__ This should be inviolate Inline-Files-0.68/demo/demo_persistence.pl0000755000076500000240000000062007303367146017355 0ustar ambsstaffuse 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.68/demo/demo_persistence_simple.pl0000755000076500000240000000040207303367146020724 0ustar ambsstaffuse 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.68/demo/demo_simple.pl0000755000076500000240000000063707303367146016332 0ustar ambsstaffuse 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.68/demo/demo_singles.pl0000755000076500000240000000034507303367146016501 0ustar ambsstaffuse 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.68/demo/demo_virtual.pl0000755000076500000240000000073007303367146016521 0ustar ambsstaffuse 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.68/demo/demo_write.pl0000755000076500000240000000014007303367146016160 0ustar ambsstaffuse Inline::Files; print VIRTUAL "This should work"; __VIRTUAL__ This should not be inviolate Inline-Files-0.68/demo/demo_XML0000755000076500000240000000032407303367146015060 0ustar ambsstaffuse 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.68/demo/XML.xml0000755000076500000240000000036307303367146014656 0ustar ambsstaff 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.68/lib/0000755000076500000240000000000011612613351013277 5ustar ambsstaffInline-Files-0.68/lib/Inline/0000755000076500000240000000000011612613351014515 5ustar ambsstaffInline-Files-0.68/lib/Inline/Files/0000755000076500000240000000000011612613351015557 5ustar ambsstaffInline-Files-0.68/lib/Inline/Files/Virtual.pm0000755000076500000240000004476211521512305017557 0ustar ambsstaffpackage Inline::Files::Virtual; $VERSION = '0.53'; 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.68/lib/Inline/Files.pm0000755000076500000240000002452511612613225016130 0ustar ambsstaffpackage Inline::Files; $VERSION = '0.68'; 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(@_); $DB::single = 1; 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.68 of Inline::Files, released July 23, 2011. =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.68/Makefile.PL0000755000076500000240000000063711612613164014516 0ustar ambsstaff 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, }, ); Inline-Files-0.68/MANIFEST0000755000076500000240000000126011612613351013664 0ustar ambsstaffChanges 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 META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Inline-Files-0.68/META.json0000644000076500000240000000162711612613351014160 0ustar ambsstaff{ "abstract" : "Multiple virtual files at the end of your code", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.58, CPAN::Meta::Converter version 2.110930", "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", "version" : "0.68" } Inline-Files-0.68/META.yml0000644000076500000240000000077511612613351014013 0ustar ambsstaff--- 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 6.58, CPAN::Meta::Converter version 2.110930' 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 version: 0.68 Inline-Files-0.68/README0000755000076500000240000000336107664773234013442 0ustar ambsstaff============================================================================== Release of version 0.62 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) ============================================================================== CHANGES IN VERSION 0.52 (No changes have been documented for this version) ============================================================================== AVAILABILITY Inline::Files has been uploaded to the CPAN and is also available from: http://www.csse.monash.edu.au/~damian/CPAN/Inline-Files.tar.gz ============================================================================== ============================================================================== CHANGES IN VERSION 0.62 ============================================================================== AVAILABILITY Inline::Files has been uploaded to the CPAN ============================================================================== Inline-Files-0.68/t/0000755000076500000240000000000011612613351012774 5ustar ambsstaffInline-Files-0.68/t/00init.t0000755000076500000240000000046611605557062014305 0ustar ambsstaffuse 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.68/t/01basics.t0000644000076500000240000000070611612613347014576 0ustar ambsstaffuse 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.68/t/02write.t0000644000076500000240000000073611612613347014470 0ustar ambsstaffuse 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.68/t/03nowrite.t0000444000076500000240000000110411612613347015012 0ustar ambsstaffuse 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" : 0, $text !~ /__MYFILE__\nNew stuff\n$/ ); } __MYFILE__ Old stuff Inline-Files-0.68/t/04create.t0000644000076500000240000000134011612613347014573 0ustar ambsstaffuse 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.68/t/05seek.t0000644000076500000240000000163011612613347014262 0ustar ambsstaffuse 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.68/t/06backup.t0000644000076500000240000000137011612613347014602 0ustar ambsstaffuse 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.68/t/07hash.t0000644000076500000240000000124311612613347014260 0ustar ambsstaffuse 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.68/t/08coreopen.t0000644000076500000240000000202711605557110015146 0ustar ambsstaff# -*- 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.68/tests/0000755000076500000240000000000011612613351013673 5ustar ambsstaffInline-Files-0.68/tests/01basics.t0000755000076500000240000000070611605557042015501 0ustar ambsstaffuse 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.68/tests/02write.t0000755000076500000240000000073511605557044015374 0ustar ambsstaffuse 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.68/tests/03nowrite.t0000755000076500000240000000110411605557046015723 0ustar ambsstaffuse 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" : 0, $text !~ /__MYFILE__\nNew stuff\n$/ ); } __MYFILE__ Old stuff Inline-Files-0.68/tests/04create.t0000755000076500000240000000127211605557050015501 0ustar ambsstaffuse 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.68/tests/05seek.t0000755000076500000240000000163011605557051015165 0ustar ambsstaffuse 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.68/tests/06backup.t0000755000076500000240000000136711605557053015515 0ustar ambsstaffuse 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.68/tests/07hash.t0000755000076500000240000000124311605560144015160 0ustar ambsstaffuse 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