Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

enabling wizards

by pc88mxer (Vicar)
on May 22, 2008 at 23:35 UTC ( #688062=perlmeditation: print w/replies, xml ) Need Help??

After consulting the DBI documentation for the umpteenth time to remind myself what parameters go where, I finally decided there had to be a better way. Pondering the problem for a while, I decided that what I really wanted was to be able to write something like this:
use Resource; my $dbh = resource(isa => 'DBI'); ...
When the script is first run a dialog pops up informing me that I need to specify a database connection. It can present a list of connections I've used before or guide me through the creation of a new one. I can also have the setting I select remembered for future runs.

Generalizing this idea, consider the power of this three line program:

my $in = resource(isa => 'ArrayReader'); my $out = resource(isa => 'ArrayWriter'); while ($_ = $in->next) { $out->write($_) }
An ArrayReader is just a generator which creates array refs. For instance, it could represent
  • data from a CSV file
  • the result set of an SQL query
  • an HTML table scraped from a remote web site
  • ...
And, of course, an ArrayWriter is simply something that serializes an array ref.

The point is that once we have this specification we can write a helper program (or 'wizard') to guide the user through the process of creating the ArrayReader and ArrayWriter objects. This frees them from having to remember (or even learn) how to parse a CSV file or invoke a database query, etc. Moreover, the program is now much more general and useful as new wizards for ArrayReader and ArrayWriter objects are implemented.

This is just a preliminary expression of the idea, but I think it really could be worth developing. Comments?

Replies are listed 'Best First'.
Re: enabling wizards
by Anonymous Monk on May 23, 2008 at 01:13 UTC

    The generalized stub could be

    use Resource; my $exitcode = resource(isa => 'Program');

    which when run the first time, would remind me that I haven't yet written any code and would guide me through the process, offering snippets I've previously written, etc...


Re: enabling wizards
by holli (Monsignor) on May 22, 2008 at 23:58 UTC
    I would definitly separate the database connection thing from the reader/writer problem. Let code speak:
    use Connect qw( autoconnect ); use Resource; # displays dialog and saves answer in ./ my $dbh = autoconnect(); #could also use dbi => $connection_string here my $dbr = resource( type => 'perl/dbi', dbh = $dbh, table => 'users' ) +; my $txt = resource( type => 'perl/csvxs', delimiter => ';', file => 'f +oo.txt' ); #while ($_ = $dbr->reader->next ) { # $txt->writer->out(@$_[0,1]) #} while ($_ = $dbr->reader->nexth ) { $txt->writer->out($_->{id}, $_->{name}) }

    holli, /regexed monk/
Re: enabling wizards
by dragonchild (Archbishop) on May 23, 2008 at 00:15 UTC
    IO::All does a lot of this already. Not the wizard part so much as the almost mind-reading part.

    As for the wizard part, I don't know so much about the popup part, but I would think that DBM::Deep would be useful in keeping track of what's happened in the past.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: enabling wizards
by ioannis (Monsignor) on May 25, 2008 at 12:13 UTC
    For storage, why not use the pg_service.conf and .pgpass file? These are the standard Postgres file formats that remember connections parameters, and are easy to load into arrayref. The pg_service.conf is in ini format (use Config::Format::Ini). Postgres users would love to use a module that read from the same configuration files they already have.
Re: enabling wizards
by mr_mischief (Monsignor) on May 28, 2008 at 20:33 UTC
    Your wizards are great if they gather the information from the user once and use it multiple times until a configuration change is necessary. If the user must manually configure a program through a wizard every time, it would quickly get annoying.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://688062]
Approved by holli
Front-paged by grinder
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-05-24 16:31 GMT
Find Nodes?
    Voting Booth?