From 4aee638ca0827f3a9439f5f40eee18fbe11c89e2 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 11 Mar 2005 10:21:26 +0000 Subject: [PATCH] Storable! 0.24! --- Changes | 2 +- DBSchema.pm | 39 ++++++++++++++++++++++----------------- Makefile.PL | 1 + README | 6 +++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Changes b/Changes index f3e0d5b..e4ecd42 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,6 @@ Revision history for Perl extension DBIx::DBSchema. -0.24 unreleased +0.24 Fri Mar 11 02:20:55 PST 2005 - Oracle driver from Daniel Hanks and Peter Bowen . - Switch from FreezeThaw to Storable, keep ability to read old files diff --git a/DBSchema.pm b/DBSchema.pm index fc4916d..96aa843 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -5,7 +5,7 @@ use vars qw(@ISA $VERSION); #use Exporter; use Carp qw(confess); use DBI; -use FreezeThaw qw(freeze thaw cmpStr); +use Storable; use DBIx::DBSchema::Table; use DBIx::DBSchema::Column; use DBIx::DBSchema::ColGroup::Unique; @@ -14,7 +14,7 @@ use DBIx::DBSchema::ColGroup::Index; #@ISA = qw(Exporter); @ISA = (); -$VERSION = "0.23"; +$VERSION = "0.24"; =head1 NAME @@ -136,12 +136,23 @@ Loads a DBIx::DBSchema object from a file. sub load { my($proto,$file)=@_; #use $proto ? - open(FILE,"<$file") or die "Can't open $file: $!"; - my($string)=join('',); #can $string have newlines? pry not? - close FILE or die "Can't close $file: $!"; - my($self)=thaw $string; - #no bless needed? + + my $self; + + #first try Storable + eval { $self = Storable::retrieve($file); }; + + if ( $@ && $@ =~ /not.*storable/i ) { #then try FreezeThaw + eval "use FreezeThaw;"; + die $@ if $@; + open(FILE,"<$file") or die "Can't open $file: $!"; + my $string = join('',); + close FILE or die "Can't close $file: $!"; + ($self) = FreezeThaw::thaw($string); + } + $self; + } =item save FILENAME @@ -151,14 +162,8 @@ Saves a DBIx::DBSchema object to a file. =cut sub save { - my($self,$file)=@_; - my($string)=freeze $self; - open(FILE,">$file") or die "Can't open $file: $!"; - print FILE $string; - close FILE or die "Can't close file: $!"; - my($check_self)=thaw $string; - die "Verify error: Can't freeze and thaw dbdef $self" - if (cmpStr($self,$check_self)); + #my($self, $file) = @_; + Storable::nstore(@_); } =item addtable TABLE_OBJECT @@ -268,7 +273,7 @@ sub pretty_print { ). " ],\n" #" 'index' => [ ". " ],\n" } $self->tables - ), "}\n"; + ). "}\n"; } =cut @@ -337,7 +342,7 @@ Charles Shapiro and Mitchell Friedman =head1 COPYRIGHT -Copyright (c) 2000 Ivan Kohler +Copyright (c) 2000-2005 Ivan Kohler Copyright (c) 2000 Mail Abuse Prevention System LLC All rights reserved. This program is free software; you can redistribute it and/or modify it under diff --git a/Makefile.PL b/Makefile.PL index a10e4da..14c04d4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -7,5 +7,6 @@ WriteMakefile( 'PREREQ_PM' => { 'DBI' => 0, 'FreezeThaw' => 0, + 'Storable' => 0, }, ); diff --git a/README b/README index 4e41f8b..6d3b137 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ DBIx::DBSchema -Copyright (c) 2000-2004 Ivan Kohler +Copyright (c) 2000-2005 Ivan Kohler Copyright (c) 2000 Mail Abuse Prevention System LLC All rights reserved. This program is free software; you can redistribute it and/or modify it under @@ -12,7 +12,7 @@ schema from an existing database. You can save the schema to disk and restore it from different process. Most importantly, DBIx::DBSchema can write SQL CREATE statements for different databases from a single source. -Currently supported databases are MySQL, PostgreSQL, Sybase and Oracle. +Currently supported databases are MySQL, PostgreSQL, Oracle and Sybase. DBIx::DBSchema will attempt to use generic SQL syntax for other databases. Assistance adding support for other databases is welcomed. See the DBIx::DBSchema::DBD manpage, "Driver Writer's Guide and Base Class". @@ -39,4 +39,4 @@ A mailing list is available. Send a blank message to Homepage: -$Id: README,v 1.10 2004-02-26 01:34:24 ivan Exp $ +$Id: README,v 1.11 2005-03-11 10:17:53 ivan Exp $ -- 2.20.1