29a300e58e3a74a403f9c9c8b59d940f8ad7d2ba
[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 @EXPORT_OK);
44 $DEBUG = 0 unless defined $DEBUG;
45
46 use Storable;
47 use Exporter;
48 use SQL::Translator::Utils qw(debug normalize_name);
49
50 use base qw(Exporter);
51
52 @EXPORT_OK = qw(parse);
53
54 sub parse {
55     my ($translator, $data) = @_;
56
57     if (defined($data)) {
58         $translator->{'schema'} = Storable::thaw($data);
59         return 1;
60     } elsif (defined($translator->filename)) {
61         $translator->{'schema'} = Storable::retrieve($translator->filename);
62         return 1;
63     }
64
65     return 0;
66 }
67
68 1;
69
70 # -------------------------------------------------------------------
71
72 =pod
73
74 =head1 SEE ALSO
75
76 SQL::Translator.
77
78 =head1 AUTHOR
79
80 Paul Harrington E<lt>harringp@deshaw.comE<gt>.
81
82 =cut