1 package SQL::Translator;
4 our ( $DEFAULT_SUB, $DEBUG, $ERROR );
6 our $VERSION = '0.11021';
7 $DEBUG = 0 unless defined $DEBUG;
10 use Carp qw(carp croak);
14 use File::Spec::Functions qw(catfile);
15 use File::Basename qw(dirname);
17 use Sub::Quote qw(quote_sub);
18 use SQL::Translator::Producer;
19 use SQL::Translator::Schema;
20 use SQL::Translator::Utils qw(throw ex2err carp_ro normalize_quote_options);
22 $DEFAULT_SUB = sub { $_[0]->schema } unless defined $DEFAULT_SUB;
25 SQL::Translator::Role::Debug
26 SQL::Translator::Role::Error
27 SQL::Translator::Role::BuildArgs
30 around BUILDARGS => sub {
33 my $config = $self->$orig(@_);
35 # If a 'parser' or 'from' parameter is passed in, use that as the
36 # parser; if a 'producer' or 'to' parameter is passed in, use that
37 # as the producer; both default to $DEFAULT_SUB.
38 $config->{parser} ||= $config->{from} if defined $config->{from};
39 $config->{producer} ||= $config->{to} if defined $config->{to};
41 $config->{filename} ||= $config->{file} if defined $config->{file};
43 my $quote = normalize_quote_options($config);
44 $config->{quote_identifiers} = $quote if defined $quote;
51 # Make sure all the tool-related stuff is set up
52 foreach my $tool (qw(producer parser)) {
53 $self->$tool($self->$tool);
59 default => quote_sub(q{ 0 }),
60 coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
61 ) foreach qw(add_drop_table no_comments show_warnings trace validate);
63 # quote_identifiers is on by default, use a 0-but-true as indicator
64 # so we can allow individual producers to change the default
65 has quote_identifiers => (
67 default => quote_sub(q{ '0E0' }),
68 coerce => quote_sub(q{ $_[0] || 0 }),
71 sub quote_table_names {
72 (@_ > 1 and ($_[1] xor $_[0]->quote_identifiers) )
73 ? croak 'Using quote_table_names as a setter is no longer supported'
74 : $_[0]->quote_identifiers;
77 sub quote_field_names {
78 (@_ > 1 and ($_[1] xor $_[0]->quote_identifiers) )
79 ? croak 'Using quote_field_names as a setter is no longer supported'
80 : $_[0]->quote_identifiers;
83 after quote_identifiers => sub {
85 # synchronize for old code reaching directly into guts
86 $_[0]->{quote_table_names}
87 = $_[0]->{quote_field_names}
92 has producer => ( is => 'rw', default => sub { $DEFAULT_SUB } );
94 around producer => sub {
99 path => "SQL::Translator::Producer",
100 default_sub => "produce",
104 has producer_type => ( is => 'rwp', init_arg => undef );
106 around producer_type => carp_ro('producer_type');
108 has producer_args => ( is => 'rw', default => quote_sub(q{ +{} }) );
110 around producer_args => sub {
112 shift->_args($orig, @_);
115 has parser => ( is => 'rw', default => sub { $DEFAULT_SUB } );
117 around parser => sub {
122 path => "SQL::Translator::Parser",
123 default_sub => "parse",
127 has parser_type => ( is => 'rwp', init_arg => undef );
129 around parser_type => carp_ro('parser_type');
131 has parser_args => ( is => 'rw', default => quote_sub(q{ +{} }) );
133 around parser_args => sub {
135 shift->_args($orig, @_);
140 default => quote_sub(q{ [] }),
143 # Set. Convert args to list of [\&code,@args]
144 foreach (@{$_[0]||[]}) {
145 my ($filt,@args) = ref($_) eq "ARRAY" ? @$_ : $_;
146 if ( isa($filt,"CODE") ) {
147 push @filters, [$filt,@args];
151 __PACKAGE__->debug("Adding $filt filter. Args:".Dumper(\@args)."\n") if __PACKAGE__->debugging;
152 $filt = _load_sub("$filt\::filter", "SQL::Translator::Filter")
153 || throw(__PACKAGE__->error);
154 push @filters, [$filt,@args];
161 around filters => sub {
164 return @{$self->$orig([@{$self->$orig}, @_])} if @_;
165 return @{$self->$orig};
171 foreach my $filename (ref($_[0]) eq 'ARRAY' ? @{$_[0]} : $_[0]) {
173 throw("Cannot use directory '$filename' as input source");
175 elsif (not -f _ && -r _) {
176 throw("Cannot use '$filename' as input source: ".
177 "file does not exist or is not readable.");
183 around filename => \&ex2err;
190 # Set $self->data based on what was passed in. We will
191 # accept a number of things; do our best to get it right.
193 if (isa($data, 'ARRAY')) {
194 $data = join '', @$data;
196 elsif (isa($data, 'GLOB')) {
197 seek ($data, 0, 0) if eof ($data);
201 return isa($data, 'SCALAR') ? $data : \$data;
209 if (@_ > 1 && !ref $_[0]) {
210 return $self->$orig(\join('', @_));
213 return $self->$orig(@_);
215 return ex2err($orig, $self);
220 # If we have a filename but no data yet, populate.
221 if (my $filename = $self->filename) {
222 $self->debug("Opening '$filename' to get contents.\n");
226 my @files = ref($filename) eq 'ARRAY' ? @$filename : ($filename);
228 foreach my $file (@files) {
229 open my $fh, '<', $file
230 or throw("Can't read file '$file': $!");
234 close $fh or throw("Can't close file '$file': $!");
245 predicate => '_has_schema',
248 around schema => carp_ro('schema');
250 around reset => sub {
257 sub _build_schema { SQL::Translator::Schema->new(translator => shift) }
261 my ($args, $parser, $parser_type, $producer, $producer_type);
262 my ($parser_output, $producer_output, @producer_output);
266 # Passed a reference to a hash?
267 if (isa($_[0], 'HASH')) {
269 $self->debug("translate: Got a hashref\n");
273 # Passed a GLOB reference, i.e., filehandle
274 elsif (isa($_[0], 'GLOB')) {
275 $self->debug("translate: Got a GLOB reference\n");
279 # Passed a reference to a string containing the data
280 elsif (isa($_[0], 'SCALAR')) {
281 # passed a ref to a string
282 $self->debug("translate: Got a SCALAR reference (string)\n");
286 # Not a reference; treat it as a filename
287 elsif (! ref $_[0]) {
288 # Not a ref, it's a filename
289 $self->debug("translate: Got a filename\n");
290 $self->filename($_[0]);
293 # Passed something else entirely.
295 # We're not impressed. Take your empty string and leave.
298 # Actually, if data, parser, and producer are set, then we
299 # can continue. Too bad, because I like my comment
301 return "" unless ($self->data &&
307 # You must pass in a hash, or you get nothing.
312 # ----------------------------------------------------------------------
313 # Can specify the data to be transformed using "filename", "file",
314 # "data", or "datasource".
315 # ----------------------------------------------------------------------
316 if (my $filename = ($args->{'filename'} || $args->{'file'})) {
317 $self->filename($filename);
320 if (my $data = ($args->{'data'} || $args->{'datasource'})) {
324 # ----------------------------------------------------------------
326 # ----------------------------------------------------------------
327 my $data = $self->data;
329 # ----------------------------------------------------------------
330 # Local reference to the parser subroutine
331 # ----------------------------------------------------------------
332 if ($parser = ($args->{'parser'} || $args->{'from'})) {
333 $self->parser($parser);
335 $parser = $self->parser;
336 $parser_type = $self->parser_type;
338 # ----------------------------------------------------------------
339 # Local reference to the producer subroutine
340 # ----------------------------------------------------------------
341 if ($producer = ($args->{'producer'} || $args->{'to'})) {
342 $self->producer($producer);
344 $producer = $self->producer;
345 $producer_type = $self->producer_type;
347 # ----------------------------------------------------------------
348 # Execute the parser, the filters and then execute the producer.
349 # Allowances are made for each piece to die, or fail to compile,
350 # since the referenced subroutines could be almost anything. In
351 # the future, each of these might happen in a Safe environment,
352 # depending on how paranoid we want to be.
353 # ----------------------------------------------------------------
356 unless ( $self->_has_schema ) {
357 eval { $parser_output = $parser->($self, $$data) };
358 if ($@ || ! $parser_output) {
359 my $msg = sprintf "translate: Error with parser '%s': %s",
360 $parser_type, ($@) ? $@ : " no results";
361 return $self->error($msg);
364 $self->debug("Schema =\n", Dumper($self->schema), "\n") if $self->debugging;;
366 # Validate the schema if asked to.
367 if ($self->validate) {
368 my $schema = $self->schema;
369 return $self->error('Invalid schema') unless $schema->is_valid;
374 foreach ($self->filters) {
376 my ($code,@args) = @$_;
377 eval { $code->($self->schema, @args) };
378 my $err = $@ || $self->error || 0;
379 return $self->error("Error with filter $filt_num : $err") if $err;
383 # Calling wantarray in the eval no work, wrong scope.
384 my $wantarray = wantarray ? 1 : 0;
387 @producer_output = $producer->($self);
389 $producer_output = $producer->($self);
392 if ($@ || !( $producer_output || @producer_output)) {
393 my $err = $@ || $self->error || "no results";
394 my $msg = "translate: Error with producer '$producer_type': $err";
395 return $self->error($msg);
398 return wantarray ? @producer_output : $producer_output;
402 return shift->_list("parser");
406 return shift->_list("producer");
410 # ======================================================================
412 # ======================================================================
414 # ----------------------------------------------------------------------
415 # _args($type, \%args);
417 # Gets or sets ${type}_args. Called by parser_args and producer_args.
418 # ----------------------------------------------------------------------
424 # If the first argument is an explicit undef (remember, we
425 # don't get here unless there is stuff in @_), then we clear
426 # out the producer_args hash.
427 if (! defined $_[0]) {
432 my $args = isa($_[0], 'HASH') ? shift : { @_ };
433 return $self->$orig({ %{$self->$orig}, %$args });
439 # ----------------------------------------------------------------------
440 # Does the get/set work for parser and producer. e.g.
441 # return $self->_tool({
442 # name => 'producer',
443 # path => "SQL::Translator::Producer",
444 # default_sub => "produce",
446 # ----------------------------------------------------------------------
448 my ($self,$args) = (shift, shift);
449 my $name = $args->{name};
450 my $orig = $args->{orig};
451 return $self->{$name} unless @_; # get accessor
453 my $path = $args->{path};
454 my $default_sub = $args->{default_sub};
457 # passed an anonymous subroutine reference
458 if (isa($tool, 'CODE')) {
460 $self->${\"_set_${name}_type"}("CODE");
461 $self->debug("Got $name: code ref\n");
464 # Module name was passed directly
465 # We try to load the name; if it doesn't load, there's a
466 # possibility that it has a function name attached to it,
467 # so we give it a go.
469 $tool =~ s/-/::/g if $tool !~ /::/;
471 ($code,$sub) = _load_sub("$tool\::$default_sub", $path);
473 if ( __PACKAGE__->error =~ m/Can't find module/ ) {
474 # Mod not found so try sub
475 ($code,$sub) = _load_sub("$tool", $path) unless $code;
476 die "Can't load $name subroutine '$tool' : ".__PACKAGE__->error
480 die "Can't load $name '$tool' : ".__PACKAGE__->error;
484 # get code reference and assign
485 my (undef,$module,undef) = $sub =~ m/((.*)::)?(\w+)$/;
487 $self->${\"_set_$name\_type"}($sub eq "CODE" ? "CODE" : $module);
488 $self->debug("Got $name: $sub\n");
491 # At this point, $self->{$name} contains a subroutine
492 # reference that is ready to run
494 # Anything left? If so, it's args
495 my $meth = "$name\_args";
496 $self->$meth(@_) if (@_);
498 return $self->{$name};
501 # ----------------------------------------------------------------------
503 # ----------------------------------------------------------------------
506 my $type = shift || return ();
507 my $uctype = ucfirst lc $type;
510 # First find all the directories where SQL::Translator
511 # parsers or producers (the "type") appear to live.
513 load("SQL::Translator::$uctype") or return ();
514 my $path = catfile "SQL", "Translator", $uctype;
517 my $dir = catfile $_, $path;
518 $self->debug("_list_${type}s searching $dir\n");
524 # Now use File::File::find to look recursively in those
525 # directories for all the *.pm files, then present them
526 # with the slashes turned into dashes.
531 if ( -f && m/\.pm$/ ) {
534 my $cur_dir = $File::Find::dir;
535 my $base_dir = quotemeta catfile 'SQL', 'Translator', $uctype;
538 # See if the current directory is below the base directory.
540 if ( $cur_dir =~ m/$base_dir(.*)/ ) {
542 $cur_dir =~ s!^/!!; # kill leading slash
543 $cur_dir =~ s!/!-!g; # turn other slashes into dashes
549 $found{ join '-', map { $_ || () } $cur_dir, $mod } = 1;
555 return sort { lc $a cmp lc $b } keys %found;
558 # ----------------------------------------------------------------------
559 # load(MODULE [,PATH[,PATH]...])
561 # Loads a Perl module. Short circuits if a module is already loaded.
563 # MODULE - is the name of the module to load.
565 # PATH - optional list of 'package paths' to look for the module in. e.g
566 # If you called load('Super::Foo' => 'My', 'Other') it will
567 # try to load the mod Super::Foo then My::Super::Foo then Other::Super::Foo.
569 # Returns package name of the module actually loaded or false and sets error.
571 # Note, you can't load a name from the root namespace (ie one without '::' in
572 # it), therefore a single word name without a path fails.
573 # ----------------------------------------------------------------------
577 push @path, "" if $name =~ /::/; # Empty path to check name on its own first
578 push @path, @_ if @_;
581 my $module = $_ ? "$_\::$name" : $name;
582 my $file = $module; $file =~ s[::][/]g; $file .= ".pm";
583 __PACKAGE__->debug("Loading $name as $file\n");
584 return $module if $INC{$file}; # Already loaded
586 eval { require $file };
587 next if $@ =~ /Can't locate $file in \@INC/;
588 eval { $module->import() } unless $@;
589 return __PACKAGE__->error("Error loading $name as $module : $@")
590 if $@ && $@ !~ /"SQL::Translator::Producer" is not exported/;
592 return $module; # Module loaded ok
595 return __PACKAGE__->error("Can't find module $name. Path:".join(",",@path));
598 # ----------------------------------------------------------------------
599 # Load the sub name given (including package), optionally using a base package
600 # path. Returns code ref and name of sub loaded, including its package.
601 # (\&code, $sub) = load_sub( 'MySQL::produce', "SQL::Translator::Producer" );
602 # (\&code, $sub) = load_sub( 'MySQL::produce', @path );
603 # ----------------------------------------------------------------------
605 my ($tool, @path) = @_;
607 my (undef,$module,$func_name) = $tool =~ m/((.*)::)?(\w+)$/;
608 if ( my $module = load($module => @path) ) {
609 my $sub = "$module\::$func_name";
610 return wantarray ? ( \&{ $sub }, $sub ) : \&$sub;
615 sub format_table_name {
616 return shift->_format_name('_format_table_name', @_);
619 sub format_package_name {
620 return shift->_format_name('_format_package_name', @_);
624 return shift->_format_name('_format_fk_name', @_);
628 return shift->_format_name('_format_pk_name', @_);
631 # ----------------------------------------------------------------------
632 # The other format_*_name methods rely on this one. It optionally
633 # accepts a subroutine ref as the first argument (or uses an identity
634 # sub if one isn't provided or it doesn't already exist), and applies
635 # it to the rest of the arguments (if any).
636 # ----------------------------------------------------------------------
642 if (ref($args[0]) eq 'CODE') {
643 $self->{$field} = shift @args;
645 elsif (! exists $self->{$field}) {
646 $self->{$field} = sub { return shift };
649 return @args ? $self->{$field}->(@args) : $self->{$field};
653 my ($ref, $type) = @_;
654 return UNIVERSAL::isa($ref, $type);
662 # Must come after all 'has' declarations
663 around new => \&ex2err;
667 # ----------------------------------------------------------------------
668 # Who killed the pork chops?
669 # What price bananas?
672 # ----------------------------------------------------------------------
678 SQL::Translator - manipulate structured data definitions (SQL and more)
684 my $translator = SQL::Translator->new(
687 # Print Parse::RecDescent trace
689 # Don't include comments in output
691 # Print name mutations, conflicts
693 # Add "drop table" statements
695 # to quote or not to quote, thats the question
696 quote_identifiers => 1,
697 # Validate schema object
699 # Make all table names CAPS in producers which support this option
700 format_table_name => sub {my $tablename = shift; return uc($tablename)},
701 # Null-op formatting, only here for documentation's sake
702 format_package_name => sub {return shift},
703 format_fk_name => sub {return shift},
704 format_pk_name => sub {return shift},
707 my $output = $translator->translate(
710 # Or an arrayref of filenames, i.e. [ $file1, $file2, $file3 ]
712 ) or die $translator->error;
718 This documentation covers the API for SQL::Translator. For a more general
719 discussion of how to use the modules and scripts, please see
720 L<SQL::Translator::Manual>.
722 SQL::Translator is a group of Perl modules that converts
723 vendor-specific SQL table definitions into other formats, such as
724 other vendor-specific SQL, ER diagrams, documentation (POD and HTML),
725 XML, and Class::DBI classes. The main focus of SQL::Translator is
726 SQL, but parsers exist for other structured data formats, including
727 Excel spreadsheets and arbitrarily delimited text files. Through the
728 separation of the code into parsers and producers with an object model
729 in between, it's possible to combine any parser with any producer, to
730 plug in custom parsers or producers, or to manipulate the parsed data
731 via the built-in object model. Presently only the definition parts of
732 SQL are handled (CREATE, ALTER), not the manipulation of data (INSERT,
739 The constructor is called C<new>, and accepts a optional hash of options.
786 quote_table_names (DEPRECATED)
790 quote_field_names (DEPRECATED)
806 All options are, well, optional; these attributes can be set via
807 instance methods. Internally, they are; no (non-syntactical)
808 advantage is gained by passing options to the constructor.
812 =head2 add_drop_table
814 Toggles whether or not to add "DROP TABLE" statements just before the
817 =head2 quote_identifiers
819 Toggles whether or not to quote identifiers (table, column, constraint, etc.)
820 with a quoting mechanism suitable for the chosen Producer. The default (true)
823 =head2 quote_table_names
825 DEPRECATED - A legacy proxy to L</quote_identifiers>
827 =head2 quote_field_names
829 DEPRECATED - A legacy proxy to L</quote_identifiers>
833 Toggles whether to print comments in the output. Accepts a true or false
834 value, returns the current value.
838 The C<producer> method is an accessor/mutator, used to retrieve or
839 define what subroutine is called to produce the output. A subroutine
840 defined as a producer will be invoked as a function (I<not a method>)
841 and passed its container C<SQL::Translator> instance, which it should
842 call the C<schema> method on, to get the C<SQL::Translator::Schema>
843 generated by the parser. It is expected that the function transform the
844 schema structure to a string. The C<SQL::Translator> instance is also useful
845 for informational purposes; for example, the type of the parser can be
846 retrieved using the C<parser_type> method, and the C<error> and
847 C<debug> methods can be called when needed.
849 When defining a producer, one of several things can be passed in: A
850 module name (e.g., C<My::Groovy::Producer>), a module name relative to
851 the C<SQL::Translator::Producer> namespace (e.g., C<MySQL>), a module
852 name and function combination (C<My::Groovy::Producer::transmogrify>),
853 or a reference to an anonymous subroutine. If a full module name is
854 passed in (for the purposes of this method, a string containing "::"
855 is considered to be a module name), it is treated as a package, and a
856 function called "produce" will be invoked: C<$modulename::produce>.
857 If $modulename cannot be loaded, the final portion is stripped off and
858 treated as a function. In other words, if there is no file named
859 F<My/Groovy/Producer/transmogrify.pm>, C<SQL::Translator> will attempt
860 to load F<My/Groovy/Producer.pm> and use C<transmogrify> as the name of
861 the function, instead of the default C<produce>.
863 my $tr = SQL::Translator->new;
865 # This will invoke My::Groovy::Producer::produce($tr, $data)
866 $tr->producer("My::Groovy::Producer");
868 # This will invoke SQL::Translator::Producer::Sybase::produce($tr, $data)
869 $tr->producer("Sybase");
871 # This will invoke My::Groovy::Producer::transmogrify($tr, $data),
872 # assuming that My::Groovy::Producer::transmogrify is not a module
874 $tr->producer("My::Groovy::Producer::transmogrify");
876 # This will invoke the referenced subroutine directly, as
877 # $subref->($tr, $data);
878 $tr->producer(\&my_producer);
880 There is also a method named C<producer_type>, which is a string
881 containing the classname to which the above C<produce> function
882 belongs. In the case of anonymous subroutines, this method returns
885 Finally, there is a method named C<producer_args>, which is both an
886 accessor and a mutator. Arbitrary data may be stored in name => value
887 pairs for the producer subroutine to access:
889 sub My::Random::producer {
890 my ($tr, $data) = @_;
891 my $pr_args = $tr->producer_args();
893 # $pr_args is a hashref.
895 Extra data passed to the C<producer> method is passed to
898 $tr->producer("xSV", delimiter => ',\s*');
900 # In SQL::Translator::Producer::xSV:
901 my $args = $tr->producer_args;
902 my $delimiter = $args->{'delimiter'}; # value is ,\s*
906 The C<parser> method defines or retrieves a subroutine that will be
907 called to perform the parsing. The basic idea is the same as that of
908 C<producer> (see above), except the default subroutine name is
909 "parse", and will be invoked as C<$module_name::parse($tr, $data)>.
910 Also, the parser subroutine will be passed a string containing the
911 entirety of the data to be parsed.
913 # Invokes SQL::Translator::Parser::MySQL::parse()
914 $tr->parser("MySQL");
916 # Invokes My::Groovy::Parser::parse()
917 $tr->parser("My::Groovy::Parser");
919 # Invoke an anonymous subroutine directly
921 my $dumper = Data::Dumper->new([ $_[1] ], [ "SQL" ]);
922 $dumper->Purity(1)->Terse(1)->Deepcopy(1);
923 return $dumper->Dump;
926 There is also C<parser_type> and C<parser_args>, which perform
927 analogously to C<producer_type> and C<producer_args>
931 Set or retrieve the filters to run over the schema during the
932 translation, before the producer creates its output. Filters are sub
933 routines called, in order, with the schema object to filter as the 1st
934 arg and a hash of options (passed as a list) for the rest of the args.
935 They are free to do whatever they want to the schema object, which will be
936 handed to any following filters, then used by the producer.
938 Filters are set as an array, which gives the order they run in.
939 Like parsers and producers, they can be defined by a module name, a
940 module name relative to the SQL::Translator::Filter namespace, a module
941 name and function name together or a reference to an anonymous subroutine.
942 When using a module name a function called C<filter> will be invoked in
943 that package to do the work.
945 To pass args to the filter set it as an array ref with the 1st value giving
946 the filter (name or sub) and the rest its args. e.g.
951 # Do stuff to schema here!
954 [ "Names", table => 'lc' ],
955 [ "Foo", foo => "bar", hello => "world" ],
959 Although you normally set them in the constructor, which calls
960 through to filters. i.e.
962 my $translator = SQL::Translator->new(
966 [ "Names", table => 'lc' ],
971 See F<t/36-filters.t> for more examples.
973 Multiple set calls to filters are cumulative with new filters added to
974 the end of the current list.
976 Returns the filters as a list of array refs, the 1st value being a
977 reference to the filter sub and the rest its args.
981 Toggles whether to print warnings of name conflicts, identifier
982 mutations, etc. Probably only generated by producers to let the user
983 know when something won't translate very smoothly (e.g., MySQL "enum"
984 fields into Oracle). Accepts a true or false value, returns the
989 The C<translate> method calls the subroutine referenced by the
990 C<parser> data member, then calls any C<filters> and finally calls
991 the C<producer> sub routine (these members are described above).
992 It accepts as arguments a number of things, in key => value format,
993 including (potentially) a parser and a producer (they are passed
994 directly to the C<parser> and C<producer> methods).
996 Here is how the parameter list to C<translate> is parsed:
1002 1 argument means it's the data to be parsed; which could be a string
1003 (filename) or a reference to a scalar (a string stored in memory), or a
1004 reference to a hash, which is parsed as being more than one argument
1007 # Parse the file /path/to/datafile
1008 my $output = $tr->translate("/path/to/datafile");
1010 # Parse the data contained in the string $data
1011 my $output = $tr->translate(\$data);
1015 More than 1 argument means its a hash of things, and it might be
1016 setting a parser, producer, or datasource (this key is named
1017 "filename" or "file" if it's a file, or "data" for a SCALAR reference.
1019 # As above, parse /path/to/datafile, but with different producers
1020 for my $prod ("MySQL", "XML", "Sybase") {
1021 print $tr->translate(
1023 filename => "/path/to/datafile",
1027 # The filename hash key could also be:
1028 datasource => \$data,
1034 =head2 filename, data
1036 Using the C<filename> method, the filename of the data to be parsed
1037 can be set. This method can be used in conjunction with the C<data>
1038 method, below. If both the C<filename> and C<data> methods are
1039 invoked as mutators, the data set in the C<data> method is used.
1041 $tr->filename("/my/data/files/create.sql");
1045 my $create_script = do {
1047 open CREATE, "/my/data/files/create.sql" or die $!;
1050 $tr->data(\$create_script);
1052 C<filename> takes a string, which is interpreted as a filename.
1053 C<data> takes a reference to a string, which is used as the data to be
1054 parsed. If a filename is set, then that file is opened and read when
1055 the C<translate> method is called, as long as the data instance
1056 variable is not set.
1060 Returns the SQL::Translator::Schema object.
1064 Turns on/off the tracing option of Parse::RecDescent.
1068 Whether or not to validate the schema object after parsing and before
1073 Returns the version of the SQL::Translator release.
1077 See the included AUTHORS file:
1078 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
1080 =head1 GETTING HELP/SUPPORT
1082 If you are stuck with a problem or have doubts about a particular
1083 approach do not hesitate to contact us via any of the following
1084 options (the list is sorted by "fastest response time"):
1088 =item * IRC: irc.perl.org#sql-translator
1091 <a href="https://chat.mibbit.com/#sql-translator@irc.perl.org">(click for instant chatroom login)</a>
1093 =item * Mailing list: L<http://lists.scsys.co.uk/mailman/listinfo/dbix-class>
1095 =item * RT Bug Tracker: L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator>
1099 =head1 HOW TO CONTRIBUTE
1101 Contributions are always welcome, in all usable forms (we especially
1102 welcome documentation improvements). The delivery methods include git-
1103 or unified-diff formatted patches, GitHub pull requests, or plain bug
1104 reports either via RT or the Mailing list. Contributors are generally
1105 granted access to the official repository after their first several
1106 patches pass successful review. Don't hesitate to
1107 L<contact|/GETTING HELP/SUPPORT> us with any further questions you may
1110 This project is maintained in a git repository. The code and related tools are
1111 accessible at the following locations:
1115 =item * Official repo: L<git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git>
1117 =item * Official gitweb: L<http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Translator.git>
1119 =item * GitHub mirror: L<https://github.com/dbsrgits/SQL-Translator>
1121 =item * Authorized committers: L<ssh://dbsrgits@git.shadowcat.co.uk/sql-translator.git>
1123 =item * Travis-CI log: L<https://travis-ci.org/dbsrgits/sql-translator/builds>
1126 ↪ Stable branch CI status: <img src="https://secure.travis-ci.org/dbsrgits/sql-translator.png?branch=master"></img>
1132 Copyright 2012 the SQL::Translator authors, as listed in L</AUTHORS>.
1136 This library is free software and may be distributed under the same terms as
1141 If you find this module useful, please use
1142 L<http://cpanratings.perl.org/rate/?distribution=SQL-Translator> to rate it.
1147 L<SQL::Translator::Parser>,
1148 L<SQL::Translator::Producer>,
1149 L<Parse::RecDescent>,
1152 L<Text::RecordParser>,