skeleton checkin, largely stolen from DBIx::Class::Partitioned
Luke Saunders [Wed, 30 Jan 2008 13:28:49 +0000 (13:28 +0000)]
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/DBIx/Class/Fixtures.pm [new file with mode: 0644]
t/00-load.t [new file with mode: 0644]
t/01-new.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..428d04e
--- /dev/null
+++ b/Changes
@@ -0,0 +1,3 @@
+Revision history for DBIx-Class-Fixtures
+
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..e2acf0c
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,6 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/DBIx/Class/Fixtures.pm
+t/00-load.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..78ecf59
--- /dev/null
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME                => 'DBIx::Class::Fixtures',
+    AUTHOR              => 'Luke Saunders <luke@shadowcatsystems.co.uk>',
+    VERSION_FROM        => 'lib/DBIx/Class/Fixtures.pm',
+    PL_FILES            => {},
+    PREREQ_PM => {
+        'Test::More' => 0,
+    },
+    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+    clean               => { FILES => 'DBIx-Class-Fixtures-*' },
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..8686931
--- /dev/null
+++ b/README
@@ -0,0 +1,20 @@
+DBIx-Class-Fixtures
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+       perl Makefile.PL
+       make
+       make test
+       make install
+
+COPYRIGHT AND LICENCE
+
+Development sponsored by takkle.com
+
+Copyright (C) 2008 Luke Saunders <luke at shadowcatsystems.com>, some rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm
new file mode 100644 (file)
index 0000000..f9af4e4
--- /dev/null
@@ -0,0 +1,82 @@
+package DBIx::Class::Fixtures;
+
+use strict;
+use warnings;
+
+use DBIx::Class::Exception;
+use Class::Accessor;
+use Path::Class qw(dir file);
+use FindBin;
+use JSON::Syck qw(LoadFile);
+use Data::Dumper;
+
+use base qw(Class::Accessor);
+
+__PACKAGE__->mk_accessors(qw(config_dir));
+
+=head1 VERSION
+
+Version 1.000
+
+=cut
+
+our $VERSION = '1.000';
+
+=head1 NAME
+
+=head1 SYNOPSIS
+
+  use DBIx::Class::Fixtures;
+
+  ...
+
+  my $fixtures = DBIx::Class::Fixtures->new({ config_dir => '/home/me/app/fixture_configs' });
+
+  $fixtures->dump({
+    config => 'set_config.json',
+    schema => $source_dbic_schema,
+    directory => '/home/me/app/fixtures'
+  });
+
+  $fixtures->populate({
+    directory => '/home/me/app/fixtures',
+    ddl => '/home/me/app/sql/ddl.sql',
+    connection_details => ['dbi:mysql:dbname=app_dev', 'me', 'password']
+  });
+
+=head1 DESCRIPTION
+
+=head1 AUTHOR
+
+=head1 CONTRIBUTORS
+
+=cut
+
+
+sub new {
+  my $class = shift;
+
+  my ($params) = @_;
+  unless (ref $params eq 'HASH') {
+    return DBIx::Class::Exception->throw('first arg to DBIx::Class::Fixtures->new() must be hash ref');
+  }
+
+  unless ($params->{config_dir}) {
+    return DBIx::Class::Exception->throw('config_dir param not specified');
+  }
+
+  my $config_dir = dir($params->{config_dir});
+  unless (-e $params->{config_dir}) {
+    return DBIx::Class::Exception->throw('config_dir directory doesn\'t exist');
+  }
+
+  my $self = {
+    config_dir => $config_dir
+  };
+
+  bless $self, $class;
+
+  return $self;
+}
+
+1;
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644 (file)
index 0000000..87d2434
--- /dev/null
@@ -0,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+       use_ok( 'DBIx::Class::Fixtures' );
+}
+
+diag( "Testing DBIx::Class::Fixtures $DBIx::Class::Fixtures::VERSION, Perl $], $^X" );
diff --git a/t/01-new.t b/t/01-new.t
new file mode 100644 (file)
index 0000000..7a2764f
--- /dev/null
@@ -0,0 +1,19 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 3;
+
+my $config_dir = 't/var/configs';
+my $imaginary_config_dir = 't/var/not_there';
+
+eval {
+  DBIx::Class::Fixtures->new({ });
+};
+ok($@, 'new errors without config dir');
+
+eval {
+  DBIx::Class::Fixtures->new({ config_dir => $imaginary_config_dir });
+};
+ok($@, 'new errors with non-existent config dir');
+
+ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir }), 'object created with correct config dir');