package CatalystX::ListFramework::Builder; use strict; use warnings FATAL => 'all'; use MRO::Compat; use Devel::InnerPackage qw/list_packages/; our $VERSION = '0.42'; $VERSION = eval $VERSION; # numify for warning-free dev releases sub setup_components { my $class = shift; $class->next::method(@_); # these are the boilerplate Catalyst components for ListFramework my @packages = qw( Controller::Root Controller::Static Controller::AJAX Model::Metadata View::JSON View::TT ); # will auto-load other models, so this one is not -required- if (exists $class->config->{'Model::LFB::DBIC'}) { push @packages, 'Model::DBIC'; my $p = 'Model::LFB::DBIC'; # on the fly schema engineering if (!exists $class->config->{$p}->{schema_class}) { require DBIx::Class::Schema::Loader; die "Must have DBIx::Class::Schema::Loader version > 0.04005" if eval "$DBIx::Class::Schema::Loader::VERSION" <= 0.04005; DBIx::Class::Schema::Loader::make_schema_at( 'LFB::Loader::Schema', {}, $class->config->{$p}->{connect_info}, ); eval q{ package # hide from pause LFB::Loader::Schema; use base 'DBIx::Class::Schema'; LFB::Loader::Schema->load_classes(); 1; }; $INC{'LFB/Loader/Schema.pm'} = 'loaded'; $class->config->{$p}->{schema_class} = 'LFB::Loader::Schema'; } } foreach my $orig (@packages) { (my $p = $orig) =~ s/::/::LFB::/; my $comp = "${class}::${p}"; # require will shortcircuit and return true if the component is # already loaded unless (eval "package $class; require $comp;") { # make a component on the fly in the App namespace eval qq( package $comp; use base qw/CatalystX::ListFramework::Builder::${orig}/; 1; ); die $@ if $@; # inject entry to %INC so Perl knows this component is loaded # this is just for politeness and does not aid Catalyst (my $file = "$comp.pm") =~ s{::}{/}g; $INC{$file} = 'loaded'; # add newly created components to catalyst # must set up component and -then- call list_packages on it $class->components->{$comp} = $class->setup_component($comp); for my $m (list_packages($comp)) { $class->components->{$m} = $class->setup_component($m); } } } return 1; } 1; __END__ =head1 NAME CatalystX::ListFramework::Builder - *** DEPRECATED *** please see Catalyst::Plugin::AutoCRUD =head1 VERSION This document refers to version 0.42 of CatalystX::ListFramework::Builder =head1 WARNING This module will work, but is B. The same author has created L which should be almost a drop-in replacement for you, and has even more yummy automagic goodness. =head1 PURPOSE You have a database, and wish to have a basic web interface supporting Create, Retrieve, Update, Delete and Search, with little effort. This module, with only a few lines of configuration, is able to create such interfaces on the fly. They are a bit whizzy and all Web 2.0-ish. =head1 SYNOPSIS A configuration file somewhere on your system: # [listframeworkuser.conf] in Config::General format extjs2 /static/javascript/extjs-2 schema_class My::Database::Schema connect_info dbi:Pg:dbname=mydbname;host=mydbhost.example.com; connect_info username connect_info password AutoCommit 1 And in the CGI area of your web server: package ListFrameworkUser; use Catalyst qw(ConfigLoader +CatalystX::ListFramework::Builder); __PACKAGE__->setup; 1; Now going to the CGI area's URL will display a list of the tables in your database. Each item is a link to the web interface for that table. =head1 DESCRIPTION This module contains an application which will automatically construct a web interface for a database on the fly. The web interface supports Create, Retrieve, Update, Delete and Search operations. The interface is not written to static files on your system, and uses AJAX to act upon the database without reloading your web page (much like other Web 2.0 appliactions, for example Google Mail). Almost all the information required by the application is retrieved from the L ORM frontend to your database, which it is expected that you have already set up (although see L, below). This means that any change in database schema ought to be reflected immediately in the web interface after a page refresh. =head1 USAGE =head2 Pre-configuration You'll need to download the ExtJS Javascript Library (version 2.2+ recommended), from this web page: L. Install it to your web server in a location that it is able to serve as static content. Make a note of the path used in a URL to retrieve this content, as it will be needed in the application configuration file, below. =head2 Scenario 1: Plugin to an existing Catalyst App This mode is for when you have written your Catalyst application, but the Views are catering for the users and as an admin you'd like a more direct, secondary web interface to the database. package ListFrameworkUser; use Catalyst qw(ConfigLoader +CatalystX::ListFramework::Builder); __PACKAGE__->setup; 1; Adding C (LFB) as a plugin to your Catalyst application, as above, causes it to scan your existing Models. If any of them are built using L, they are automatically loaded. You still need to provide a small amount of configuration: extjs2 /static/javascript/extjs-2 PathPart admin First the application needs to know where your copy of ExtJS is, on the web server. Use the C option as shown above to specify the URL path to the libraries. This will be used in the templates in some way like this: