[Bast-commits] r6652 - in DBIx-Class/0.08/branches/run_file_against_storage: lib/DBIx/Class/Storage t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Fri Jun 12 15:38:14 GMT 2009


Author: jnapiorkowski
Date: 2009-06-12 15:38:14 +0000 (Fri, 12 Jun 2009)
New Revision: 6652

Modified:
   DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/run_file_against_storage/t/105-run-file-against-storage.t
Log:
more small regex tweaks and test cases

Modified: DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm	2009-06-12 15:34:13 UTC (rev 6651)
+++ DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm	2009-06-12 15:38:14 UTC (rev 6652)
@@ -2071,9 +2071,9 @@
       @parts = grep { $_ !~ /^(BEGIN|BEGIN TRANSACTION|COMMIT)/m } @parts;
       ## Some cleanup
       @parts = map {
-        $_=~s/;\s*?$comment.*?$//; ## trim off ending comments        
-        $_=~s/^\s*//g; ## trim leading whitespace
-        $_=~s/\s*$//g; ## trim ending whitespace
+        $_=~s/;\s*?$comment.*?$//m; ## trim off ending comments        
+        $_=~s/^\s*//mg; ## trim leading whitespace
+        $_=~s/\s*$//mg; ## trim ending whitespace
         $_;
       } @parts;
       push @lines, @parts;
@@ -2102,26 +2102,14 @@
 
 sub _split_line_into_statements {
   my ($self, $line) = @_;
-  
-  my $deliminator=qr{;|$};
-  my $quote=qr{['"]};
-  my $quoted=qr{$quote.+?$quote};
-  my $block=qr{$quoted|.};
-  my @parts = ($line=~m/$block*?$deliminator/xg);
-
-  return @parts;
-}
-
-sub _split_line_into_statements_new {
-  my ($self, $line) = @_;
-  my $deliminator=qr{;|$};
+  my $deliminator=qr/;|$/;
   my $maybe_quoted = qr/
     "[^"]+"
     |
     '[^']+'
     |
     .+?(?=$deliminator)
-  /;
+  /x;
 
   return ($line=~m/$maybe_quoted*?$deliminator/g);
 }

Modified: DBIx-Class/0.08/branches/run_file_against_storage/t/105-run-file-against-storage.t
===================================================================
--- DBIx-Class/0.08/branches/run_file_against_storage/t/105-run-file-against-storage.t	2009-06-12 15:34:13 UTC (rev 6651)
+++ DBIx-Class/0.08/branches/run_file_against_storage/t/105-run-file-against-storage.t	2009-06-12 15:38:14 UTC (rev 6652)
@@ -1,5 +1,5 @@
 
-use Test::More tests => 16; 
+use Test::More tests => 17; 
 use Test::Exception;
 use lib qw(t/lib);
 
@@ -20,8 +20,26 @@
 ok my $fh = $schema->storage->_normalize_fh_from_args(qw/t share basic.sql/),
   'Got good filehandle';
 
-ok my @lines = $schema->storage->_normalize_lines(<$fh>), 'Got some lines';
+my $storage = $schema->storage;
 
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc")],["aaa;", "bbb;", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;'bb1;bb2';ccc")],["aaa;", "'bb1;bb2';", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements(qq[aaa;"bb1;bb2";ccc])],["aaa;", '"bb1;bb2";', "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc;")],["aaa;", "bbb;", "ccc;", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');")],
+  ["insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');"],
+  "Correctly split";
+
+ok my @lines = $storage->_normalize_lines(<$fh>), 'Got some lines';
+
 is_deeply [@lines], [
   "CREATE TABLE cd_to_producer (",
   "cd integer NOT NULL,",
@@ -59,7 +77,7 @@
   ");",	
 	], 'Got expected lines';
 
-ok my @statements = $schema->storage->_normalize_statements_from_lines(@lines),
+ok my @statements = $storage->_normalize_statements_from_lines(@lines),
    'Got Statements';
 
 is_deeply [@statements], [
@@ -118,25 +136,11 @@
 	], 'Got expect Lines';
 	
 lives_ok {
-	$schema->storage->_execute_single_statement('insert into artist( artistid,name) values( 777777,"--commented" );');
+	$storage->_execute_single_statement('insert into artist( artistid,name) values( 777777,"--commented" );');
 } 'executed statement';
 
-ok $schema->storage->run_file_against_storage(qw/t share simple.sql/), 'executed the simple';
-ok $schema->storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
+ok $storage->run_file_against_storage(qw/t share simple.sql/), 'executed the simple';
+ok $storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
 
-my $storage = $schema->storage;
-
-is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc")],["aaa;", "bbb;", "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements("aaa;'bb1;bb2';ccc")],["aaa;", "'bb1;bb2';", "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements(qq[aaa;"bb1;bb2";ccc])],["aaa;", '"bb1;bb2";', "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc;")],["aaa;", "bbb;", "ccc;", ""],
- "Correctly split";
-
 use Data::Dump qw/dump/;
-warn dump $schema->storage->_split_line_into_statements_new("aaa;bbb;ccc");
+warn dump $storage->_split_line_into_statements("insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');");




More information about the Bast-commits mailing list