[Rt-commit] r2972 - in DBIx-SearchBuilder/trunk: . t

jesse at bestpractical.com jesse at bestpractical.com
Thu May 26 16:12:50 EDT 2005


Author: jesse
Date: Thu May 26 16:12:49 2005
New Revision: 2972

Modified:
   DBIx-SearchBuilder/trunk/   (props changed)
   DBIx-SearchBuilder/trunk/t/utils.pl
Log:
 r17729 at hualien:  jesse | 2005-05-26 16:11:07 -0400
 * Ruslan added an init_data method to t/utils.pl


Modified: DBIx-SearchBuilder/trunk/t/utils.pl
==============================================================================
--- DBIx-SearchBuilder/trunk/t/utils.pl	(original)
+++ DBIx-SearchBuilder/trunk/t/utils.pl	Thu May 26 16:12:49 2005
@@ -177,7 +177,7 @@
 
 =head2 cleanup_schema
 
-Takes C<$class> and C<$handle> and inits schema by calling
+Takes C<$class> and C<$handle> and cleanup schema by calling
 C<cleanup_schema_$driver> method of the C<$class> if method exists.
 Always returns undef.
 
@@ -195,4 +195,27 @@
 	}
 }
 
+=head2 init_data
+
+=cut
+
+sub init_data
+{
+	my ($class, $handle) = @_;
+	my @data = $class->init_data();
+	my @columns = @{ shift @data };
+	my $count = 0;
+	foreach my $values ( @data ) {
+		my %args;
+		for( my $i = 0; $i < @columns; $i++ ) {
+			$args{ $columns[$i] } = $values->[$i];
+		}
+		my $rec = $class->new( $handle );
+		my $id = $rec->Create( %args );
+		die "Couldn't create record" unless $id;
+		$count++;
+	}
+	return $count;
+}
+
 1;


More information about the Rt-commit mailing list