NAME
SQL::Beautify
SYNOPSIS
my $sql = new SQL::Beautify;
$sql->query($sql_query);
my $nice_sql = $sql->tidy;
DESCRIPTION
Beautifies SQL statements by adding line breaks indentation.
METHODS
- new(query => '', spaces => 4, space => ' ', break => "\n", wrap => {})
-
Constructor. Takes a few options.
- query => ''
-
Initialize the instance with a SQL string. Defaults to an empty string.
- spaces => 4
-
Number of spaces that make one indentation level. Defaults to 4.
- space => ' '
-
A string that is used as space. Default is an ASCII space character.
- break => "\n"
-
String that is used for linebreaks. Default is "\n".
- wrap => {}
-
Use this if you want to surround certain tokens with markup stuff. Known token types are "keywords" and "constants" for now. The value of each token type should be an array with two elements, one that is placed before the token and one that is placed behind it. For example, use make keywords red using terminal color escape sequences.
{ keywords => [ "\x1B[0;31m", "\x1B[0m" ] }
- add($more_sql)
-
Appends another chunk of SQL.
- query($query)
-
Sets the query to the new query string. Overwrites anything that was added with prior calls to query or add.
- beautify
-
Beautifies the internally saved SQL string and returns the result.
BUGS
Needs more tests.
Please report bugs in the CPAN bug tracker.
This module is not complete (known SQL keywords, special formatting of keywords), so if you want see something added, just send me a patch.
COPYRIGHT
Copyright (C) 2009 by Jonas Kramer. Published under the terms of the Artistic License 2.0.