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