added regex: to modify_records
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 6 Dec 2006 23:43:45 +0000 (23:43 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 6 Dec 2006 23:43:45 +0000 (23:43 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@784 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input.pm
t/2-input.t

index d53f135..671bbcd 100644 (file)
@@ -566,12 +566,17 @@ Generate hash with regexpes to be applied using l<filter>.
 
 sub _get_regex {
        my ($sf,$from,$to) = @_;
+       if ($from =~ m/^regex:(.+)$/) {
+               $from = $1;
+       } else {
+               $from = '\Q' . $from . '\E';
+       }
        if ($sf =~ /^\^/) {
                return
-                       's/\Q'. $sf .'\E([^\^]*?)\Q'. $from .'\E([^\^]*?)/'. $sf .'$1'. $to .'$2/';
+                       's/\Q'. $sf .'\E([^\^]*?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/';
        } else {
                return
-                       's/\Q'. $from .'\E/'. $to .'/g';
+                       's/'. $from .'/'. $to .'/g';
        }
 }
 
index 6864c03..cb3fef4 100755 (executable)
@@ -125,6 +125,8 @@ ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress
 ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)");
 ok(my $rec_p = $input->fetch, 'fetch');
 
+# modify_records
+
 ok($input->open(
        path => "$abs_path/modify_isis/LIBRI",
        modify_records => {
@@ -138,3 +140,19 @@ ok(my $rec = $input->fetch, 'fetch');
 
 cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working');
 
+diag dump($input);
+
+# break encapsulation, bad! bad!
+$input->{ll_db}->{record} = {
+       900 => 'foo ; bar ; baz',
+};
+
+$input->{modify_record} = {
+       900 => {
+               '*' => {
+                       ' ; ' => 'a',
+               }
+       }
+};
+
+diag "hacked: ",dump($input, $input->fetch);