NAME
Bigtop::ScriptHelp - A helper modules for command line utilities
SYNOPSIS
#!/usr/bin/perl
use Bigtop::ScriptHelp;
my $default = Bigtop::ScriptHelp->get_minimal_default();
my $tree = Bigtop::Parser->parse_string( $default );
# ...
my $style = 'SomeStyle'; # must live in Bigtop::ScriptHelp::Style::
my $better_default = Bigtop::ScriptHelp->get_big_default(
$style, $name, $art
);
my $better_tree = Bigtop::Parser->parse_string( $better_default );
Bigtop::ScriptHelp->augment_tree( $style, $bigtop_tree, $art );
my $new_field_label = Bigtop::ScriptHelp->default_label( $name );
DESCRIPTION
This module is used by the bigtop and tentmaker scripts. It provides convenience functions for them.
Styles
Whenever a user is building or augmenting a bigtop file, they can specify new tables and their relationships via a script help style of their choice. All the styles are modules in the Bigtop::ScriptHelp::Style:: namespace. See Bigtop::ScriptHelp::Style
for general information about styles and individual modules under its namespace for how each style works. That said, here is a list of the styles available when this was written.
Original
This is the default style.
The original style allows ASCII art pictures of database relationships. For example:
bigtop -n App 'contact<-birth_day'
But recent versions allow you to specify column names, their types, whether they are optional, and to give them literal default values. See Bigtop::ScriptHelp::Style::Original
for details. This is my favorite style (so it's no surprise that it is the default).
Pg8Live
This style must be requested:
bigtop -n App -s Pg8Live dsninfo username password
It will connect to the database described by the dsninfo with the supplied username and password and create a bigtop file from it. This will create a full AutoCRUD app for the database. The bigtop file will have all the tables, their columns including types and defaults. It will also know about all primary and foreign keys in the original database. Depending on how exotic the input database is, it will also know to autoincrement the primary key.
Writing your own style is easy. See Bigtop::ScriptHelp::Style
for the requirements and the two existing styles for examples.
METHODS
All methods are class methods.
- get_minimal_default
-
Params: app_name (optional, defaults to Sample)
Returns: a little default bigtop string suitable for initial building. It has everything you need for your app except tables and controllers.
- get_big_default
-
Params:
script help style app name a list of data for the style
Returns: a bigtop file suitable for immediately creating an app and starting it.
- augment_tree
-
Params:
script help style a Bigtop::Parser syntax tree (what you got from a parse_* method) a string of data for the style (join all elements with spaces)
Returns: nothing, but the tree you passed will be updated.
- default_label
-
Params: a new name
Returns: a default label for that name
Example of conversion: if name is birth_date, the label becomes 'Birth Date'.
- default_controller
-
Params: a new table name
Returns: a default label for that table's controller
Example of conversion: if table name is birth_date, the controller becomes 'BirthDate'.
FUNCTIONS
The following functions are meant for internal use, but you might like them too. Don't call them through the class, call them as functions.
- valid_ident
-
Exported by default.
Params: a proposed ident
Returns: true if the ident looks good, false otherwise. Note that the regex is not perfect. For instance, it will allow leading numbers. Further it absolutely will not notice if a table or controller name is reserved.
AUTHOR
Phil Crow, <crow.phil@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2006-7, Phil Crow
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.