App-AutoCRUD
view release on metacpan or search on metacpan
lib/App/AutoCRUD.pm view on Meta::CPAN
=head2 Quick demo
To see the demo distributed with this application :
cd examples/Chinook
plackup app.psgi
Then point your browser to L<http://localhost:5000>.
=head2 General startup
Create a configuration file, for example in L<YAML> format, like this :
app:
name: Test AutoCRUD
datasources :
Source1 :
dbh:
connect:
# arguments that will be passed to DBI->connect(...)
# for example :
- dbi:SQLite:dbname=some_file
- "" # user
- "" # password
- RaiseError : 1
sqlite_unicode: 1
Create a file F<crud.psgi> like this :
use App::AutoCRUD;
use YAML qw/LoadFile/;
my $config = LoadFile "/path/to/config.yaml";
my $crud = App::AutoCRUD->new(config => $config);
my $app = $crud->to_app;
Then run the app
plackup crud.psgi
or mount the app in Apache
<Location /crud>
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/crud.psgi
</Location>
and use your favorite web browser to navigate through your database.
=head1 DESCRIPTION
This module embodies a web application for Creating, Retrieving,
Updating and Deleting records in relational databases (hence the
'CRUD' acronym). The 'C<Auto>' part of the name is because the
application automatically generates and immediately uses the
components needed to work with your data -- you don't have to edit
scaffolding code. The 'C<Plack>' part of the name comes from the
L<Plack middleware framework|Plack> used to implement this application.
To connect to one or several databases, just supply a configuration
file with the connnection information, and optionally some
presentation information, and then you can directly work with the
data. Optionally, the configuration file can also specify many
additional details, like table groups, column groups, data
descriptions, etc. If more customization is needed, then you can
modify the presentation templates, or even subclass some parts of the
framework.
This application was designed to be easy to integrate with other web
resources in your organization : every table, every record, every
search form has its own URL which can be linked from other sources,
can be bookmarked, etc. This makes it a great tool for example
for adding an admin interface to an existing application : just
install AutoCRUD at a specific location within your Web server
(with appropriate access control :-).
Some distinctive features of this module, in comparison with other
CRUD applications, are :
=over
=item *
Hyperlinks between records, corresponding to foreign key
relationships in the database.
=item *
Support for update or delete of several records at once.
=item *
Support for reordering, masking, documenting tables and columns
through configuration files -- a cheap way to provide reasonable
user experience without investing into a full-fledged custom application.
=item *
Data export in Excel, YAML, JSON, XML formats
=item *
Extensibility through inheritance
=back
This application is also meant as an example for showing the
power of "Modern Perl", assembling several advanced frameworks
such as L<Moose>, L<Plack> and L<DBIx::DataModel>.
=head1 CONFIGURATION
The bare minimum for this application to run is to
get some configuration information about how to connect
to datasources. This can be done directly in Perl, like in
the test file F<t/00_autocrud.t> :
my $connect_options = {
RaiseError => 1,
sqlite_unicode => 1,
};
my $config = {
app => {
name => "SomeName"
},
datasources => {
SomeDatabase => {
dbh => {
connect => [$dbi_connect_string, $user, $passwd, $connect_options],
},
},
},
};
# instantiate the app
my $crud = App::AutoCRUD->new(config => $config);
my $app = $crud->to_app;
With this minimal information, the application will just display
tables and columns in alphabetical order. However, the configuration
may also specify many details about grouping and ordering tables
and columns; in that case, it is more convenient to use an external
format like L<YAML>, L<XML> or L<AppConfig>. Here is an excerpt from the
YAML configuration for L<Chinook|http://chinookdatabase.codeplex.com>, a
sample database distributed with this application (see the complete
example under the F<examples/Chinook> directory within this distribution) :
datasources :
Chinook :
dbh:
connect:
- "dbi:SQLite:dbname=Chinook_Sqlite_AutoIncrementPKs.sqlite"
- ""
- ""
- RaiseError: 1
sqlite_unicode: 1
tablegroups :
- name: Music
descr: Tables describing music content
node: open
tables :
- Artist
- Album
- Track
- name: Playlist
( run in 0.891 second using v1.01-cache-2.11-cpan-e1769b4cff6 )