--- nfo/perl/libs/Data/Storage/Handler/File/Basic.pm 2003/02/09 04:55:04 1.1 +++ nfo/perl/libs/Data/Storage/Handler/File/Basic.pm 2003/02/11 11:07:58 1.2 @@ -1,7 +1,10 @@ ## --------------------------------------------------------------------------- -## $Id: Basic.pm,v 1.1 2003/02/09 04:55:04 joko Exp $ +## $Id: Basic.pm,v 1.2 2003/02/11 11:07:58 joko Exp $ ## --------------------------------------------------------------------------- ## $Log: Basic.pm,v $ +## Revision 1.2 2003/02/11 11:07:58 joko +## - refactored to shortcuts::files +## ## Revision 1.1 2003/02/09 04:55:04 joko ## + initial commit ## @@ -13,10 +16,12 @@ use strict; use warnings; -use Data::Dumper; - +# FIXME: introduce some declaration here which +# *really* merges the contents of shortcuts::files +# replacing all from below require Exporter; +#use base qw( shortcuts::files Exporter ); our @ISA = qw( Exporter ); our @EXPORT_OK = qw( s2f @@ -24,121 +29,7 @@ f2s ); -sub s2f { - my $filename = shift; - my $string = shift; - open(FH, '>' . $filename); - print FH $string; - print FH "\n"; - close(FH); -} - -sub f2s { - my $filename = shift; - # read file at once (be careful with big files!!!) - open(FH, '<' . $filename); - my @buf_arr = ; - my $buf = join("", @buf_arr); - close(FH); - return $buf; -} - -sub a2f { - my $filename = shift; - my $string = shift; - open(FH, '>>' . $filename) or do { - print "Could not append to \"$filename\"!", "\n"; - print "Log-Message was: "; - print $string if $string; - print "\n"; - return; - }; - #print FH "\n"; - print FH $string; - print FH "\n"; - close(FH); - return 1; -} - -sub ris { - my $string = shift; - my $rules = shift; - - our $ris_result = 1; - - if (ref $rules eq 'HASH') { - my @re_find = keys %{$rules}; - # replace all keys with substitutes from hash "%re_table" - foreach my $find (@re_find) { - my $replace = $rules->{$find}; - $ris_result &= ($string =~ s/$find/$replace/g); - } - } - - if (ref $rules eq 'ARRAY') { - foreach my $rule (@{$rules}) { - my $find = $rule->[0]; - my $replace = $rule->[1]; - $ris_result &= ($string =~ s/$find/$replace/g); - } - } - - return $string; -} - -sub rif { - my $filename = shift; - my $rules = shift; - my $out_suffix = shift; - - my $outfile = $filename; - $outfile .= '.' . $out_suffix if ($out_suffix); - - my $buf = f2s($filename); - $buf = ris($buf, $rules); - s2f($outfile, $buf); -} - -sub findKeyEntries { - my $string = shift; - my $pattern = shift; - my @arr = split("\n", $string); - my @entries; - foreach (@arr) { - chomp; - #print "l: ", $_, "\n"; - if (m/$pattern/) { - push @entries, $1; - } - } - return \@entries; -} - -# --------------------------------- -# is a context-entry in a file? -# a "context-entry" is an entry identified -# by a certain keystring, which itself -# is detected dynamically -sub isEntryInFile { - - my $chk = shift; - my $content_current = f2s($chk->{filename}); - - # try to find all key-entries via patterns which are "entry-identifiers" - if (my @keys = @{ findKeyEntries($chk->{'out'}, $chk->{'pattern'}{'EntryIdent'}) }) { - # iterate through all "entry-identifiers" - foreach (@keys) { - my $pattern = $chk->{'pattern'}{'EntryCheck'}; - $pattern =~ s/\@\@KEY\@\@/$_/; - my $bool_AlreadyThere = ($content_current =~ m/$pattern/); - if ($bool_AlreadyThere) { - $chk->{'EntryFound'} = $_; - return 1; - } - } - } - -} +use shortcuts::files qw( s2f a2f f2s ); 1; __END__