a615a5ae99bb23fdadc0c6c892834b854642a8a5
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / Storable.pm
1 package SQL::Translator::Parser::Storable;
2
3 # -------------------------------------------------------------------
4 # $Id: Storable.pm 1440 2009-01-17 16:31:57Z jawnsy $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-2009 SQLFairy Authors
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # 02111-1307  USA
21 # -------------------------------------------------------------------
22
23 =head1 NAME
24
25 SQL::Translator::Parser::Storable - parser for Schema objects serialized
26     with the Storable module
27
28 =head1 SYNOPSIS
29
30   use SQL::Translator;
31
32   my $translator = SQL::Translator->new;
33   $translator->parser('Storable');
34
35 =head1 DESCRIPTION
36
37 Slurps in a Schema from a Storable file on disk.  You can then turn
38 the data into a database tables or graphs.
39
40 =cut
41
42 use strict;
43 use vars qw($DEBUG $VERSION @EXPORT_OK);
44 $DEBUG = 0 unless defined $DEBUG;
45 $VERSION = '1.99';
46
47 use Storable;
48 use Exporter;
49 use SQL::Translator::Utils qw(debug normalize_name);
50
51 use base qw(Exporter);
52
53 @EXPORT_OK = qw(parse);
54
55 sub parse {
56     my ($translator, $data) = @_;
57
58     if (defined($data)) {
59         $translator->{'schema'} = Storable::thaw($data);
60         return 1;
61     } elsif (defined($translator->filename)) {
62         $translator->{'schema'} = Storable::retrieve($translator->filename);
63         return 1;
64     }
65
66     return 0;
67 }
68
69 1;
70
71 # -------------------------------------------------------------------
72
73 =pod
74
75 =head1 SEE ALSO
76
77 SQL::Translator.
78
79 =head1 AUTHOR
80
81 Paul Harrington E<lt>harringp@deshaw.comE<gt>.
82
83 =cut