From: Paul Harrington Date: Wed, 8 Oct 2003 18:24:25 +0000 (+0000) Subject: Storable stuff X-Git-Tag: v0.04~110 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f65951705957aa01365a9d12136cf4df0ba2ae24;p=dbsrgits%2FSQL-Translator.git Storable stuff --- diff --git a/MANIFEST b/MANIFEST index b371edc..751ff01 100644 --- a/MANIFEST +++ b/MANIFEST @@ -18,6 +18,7 @@ lib/SQL/Translator/Parser/Excel.pm lib/SQL/Translator/Parser/MySQL.pm lib/SQL/Translator/Parser/Oracle.pm lib/SQL/Translator/Parser/PostgreSQL.pm +lib/SQL/Translator/Parser/Storable.pm lib/SQL/Translator/Parser/Sybase.pm lib/SQL/Translator/Parser/xSV.pm lib/SQL/Translator/Parser/XML.pm @@ -31,9 +32,9 @@ lib/SQL/Translator/Producer/GraphViz.pm lib/SQL/Translator/Producer/HTML.pm lib/SQL/Translator/Producer/MySQL.pm lib/SQL/Translator/Producer/Oracle.pm -lib/SQL/Translator/Producer/POD.pm lib/SQL/Translator/Producer/PostgreSQL.pm lib/SQL/Translator/Producer/SQLite.pm +lib/SQL/Translator/Producer/Storable.pm lib/SQL/Translator/Producer/Sybase.pm lib/SQL/Translator/Producer/TTSchema.pm lib/SQL/Translator/Producer/YAML.pm @@ -67,6 +68,8 @@ t/17sqlfxml-producer.t t/18ttschema-producer.t t/21xml-xmi-parser.t t/24yaml.t +t/25storable.t +t/26sybase-dbi.t t/data/Excel/t.xls t/data/mysql/Apache-Session-MySQL.sql t/data/mysql/BGEP-RE-create.sql diff --git a/lib/SQL/Translator/Parser/Storable.pm b/lib/SQL/Translator/Parser/Storable.pm new file mode 100755 index 0000000..1992e49 --- /dev/null +++ b/lib/SQL/Translator/Parser/Storable.pm @@ -0,0 +1,62 @@ +package SQL::Translator::Parser::Storable; + +# $Source: /home/faga/work/sqlfairy_svn/sqlfairy-cvsbackup/sqlfairy/lib/SQL/Translator/Parser/Storable.pm,v $ +# $Id: Storable.pm,v 1.1 2003-10-08 18:24:25 phrrngtn Exp $ + +=head1 NAME + +SQL::Translator::Parser::Storable - null parser for Schema objects that have already been created. + +=head1 SYNOPSIS + + use SQL::Translator; + use SQL::Translator::Parser::Storable; + + my $translator = SQL::Translator->new; + $translator->parser("SQL::Translator::Parser::Storable"); + +=head1 DESCRIPTION + +Slurps in a Schema from a Storable file on disk. You can then turn +the data into a database tables or graphs. + +=cut + +use strict; +use vars qw($DEBUG $VERSION @EXPORT_OK); +$DEBUG = 0 unless defined $DEBUG; +$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; + +use Storable; +use Exporter; +use SQL::Translator::Utils qw(debug normalize_name); + +use base qw(Exporter); + +@EXPORT_OK = qw(parse); + +sub parse { + my ($translator, $data) = @_; + + $translator->{'schema'} = Storable::thaw($data) + if defined($data); + + $translator->{'schema'} = Storable::retrieve($translator->filename) + if defined($translator->filename); + + return 1; +} + +1; + +=pod + +=head1 SEE ALSO + +SQL::Translator::Parser::Excel; + +=head1 AUTHORS + +Paul Harrington + +=cut diff --git a/lib/SQL/Translator/Producer/Storable.pm b/lib/SQL/Translator/Producer/Storable.pm new file mode 100755 index 0000000..76676c5 --- /dev/null +++ b/lib/SQL/Translator/Producer/Storable.pm @@ -0,0 +1,60 @@ +package SQL::Translator::Producer::Storable; + +# $Source: /home/faga/work/sqlfairy_svn/sqlfairy-cvsbackup/sqlfairy/lib/SQL/Translator/Producer/Storable.pm,v $ +# $Id: Storable.pm,v 1.1 2003-10-08 18:24:25 phrrngtn Exp $ + +=head1 NAME + +SQL::Translator::Producer::Storable - null producer for Schema objects that have already been created. + +=head1 SYNOPSIS + + use SQL::Translator; + use SQL::Translator::Producer::Storable; + + my $translator = SQL::Translator->new; + $translator->producer("SQL::Translator::Producer::Storable"); + +=head1 DESCRIPTION + +Uses Storable to serialize a schema to a string so that it can be +saved on disk or whatever. + +=cut + +use strict; +use vars qw($DEBUG $VERSION @EXPORT_OK); +$DEBUG = 0 unless defined $DEBUG; +$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; + +use Storable; +use Exporter; +use SQL::Translator::Utils qw(debug normalize_name); + +use base qw(Exporter); + +@EXPORT_OK = qw(produce); + +sub produce { + my $t = shift; + + my $args = $t->producer_args; + my $schema = $t->schema; + my $serialized = Storable::freeze($schema); + + return $serialized; +} + +1; + +=pod + +=head1 AUTHORS + +Paul Harrington + +=head1 SEE ALSO + +SQL::Translator::Parser::Excel; + +=cut diff --git a/t/25storable.t b/t/25storable.t new file mode 100755 index 0000000..fcad0de --- /dev/null +++ b/t/25storable.t @@ -0,0 +1,13 @@ +#!/usr/local/bin/perl +# vim: set ft=perl: + +# $Source: /home/faga/work/sqlfairy_svn/sqlfairy-cvsbackup/sqlfairy/t/25storable.t,v $ +# $Id: 25storable.t,v 1.1 2003-10-08 18:24:24 phrrngtn Exp $ + +use Test::More tests => 2; + +use_ok('SQL::Translator::Parser::Storable'); +use_ok('SQL::Translator::Producer::Storable'); + +1; +