lee_crites has asked for the wisdom of the Perl Monks concerning the following question:

CGI::Application::Plugin::BREAD

Howdy, y'all;

I am working through my first CGI::Application module. I kind of like what I am seeing, and would like to continue on with it. I guess I am not married to it, so other options are available, but at this moment, it is what I am working with.

I was going to write a plugin of my own that took a MySQL table name and view name, and present the user with a CRUD based page. I was going to use as defaults (if the view did not already exist) the info I could extract from the MySQL DESCRIBE command.

I could then build a CGI::App module that used a specific view (the views info kept in another table), and build as many module/view combinations as I needed.

To try to make that make more sense, say there is a user_info table. Each "view" defines which fields can be seen, and which can be edited (the rest are invisible). The "user view" allows the user to update certain fields, see certain fields but not update them, the rest are invisible to them. The sysadmin could edit and view some fields. The HR folks could view/update certain fields, etc. I know -- this is a dumb example, but it does describe what I am wanting to do with the views.

My goal is one plugin that can automagically pull all of this off.

While casting about for ideas and/or an existing plugin, I found the BREAD plugin named above. I decided to try it out, and it failed. I spent a few hours tinkering about trying to get it to work. I just kept running into undocumented requirements.

In my research into this plugin, I noted it does not seem to have had any real work done on it in 8 years. So I am guessing it is no longer valid.

So my questions:

I cannot imagine I am the first one to think of this idea and/or want to pull this kind of thing off, so I'm betting someone reading this has already invented the wheel, and is happily using it. Any help/pointers/etc would be greatly appreciated.

Thanks muchly!

Update: The environment I am using is:

Lee Crites
lee@xpeerant.com
  • Comment on Replacement for/working version of CGI::App::Plugin::BREAD ???

Replies are listed 'Best First'.
Re: Replacement for/working version of CGI::App::Plugin::BREAD ???
by lee_crites (Scribe) on Jun 18, 2013 at 16:29 UTC

    More Info / SHOW COLUMNS ISSUE

    I realize this might be considered a "new topic," and as such, should be its own entry, but since I am working through the task described in the initial message, I thought it would be good to at least start this message here.

    So... while plugging away at my own solution, I have found an issue with trying to execute either a "DESCRIBE $table" or "SHOW COLUMNS FROM $table" command. Here is an extracted snippet of code:

    my $rval = ''; my $sth2 = $dbh->prepare("SHOW COLUMNS FROM $table"); $sth2->execute() or die 'execute failed'; if ( $sth2->err ) { $rval = 'error: [' . $sth2->errstr . ']'; } else { # the "while" line is #151 from the error message... while ( my @arr = $sth2->fetchrow_arrayref() ) { $rval .= '[' . join('|', @arr ) . ']'; } }

    At this point, I am simply trying to gather ANYTHING from the command, so, yes, $rval will not have anything truly meaningful in this example.

    What I am getting is an unending stream of:

    [Tue Jun 18 10:48:43 2013] [error] [client 10.22.50.24] DBD::mysql::st fetchrow_arrayref failed: fetch() without execute() at /var/www/cgi-bin/CaMS2/TableEdit.pm line 151., referer: http://10.22.50.14/CaMS2/index.cgi

    I don't need to know how to get a list of column names -- I already have that working. I want "the rest of the story" -- the Type, Null, and Default columns for sure.

    mysql> show columns from cmsParms; +--------+-----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-----------+------+-----+---------+-------+ | pKey | char(100) | NO | PRI | NULL | | | pValue | text | NO | | NULL | | +--------+-----------+------+-----+---------+-------+ 2 rows in set (0.01 sec)

    So that's my current issue. I'm currently hacking at it. When I get a solution, I'll post it here. If, however, anyone has already crossed this bridge, and can toss me some hints/tips/tricks/etc, I would greatly appreciate it!!!

    Lee Crites
    lee@critesclan.com
      Correction ;
      #my @arr = $sth2->fetchrow_arrayref() my @arr = $sth2->fetchrow_array()
      poj

        Thanks for the tip. I found an obscure reference to fetchrow_arrayref where the person was getting the same error I was, but couldn't figure out why. The reply was something to the effect that fetchrow_arrayref has "issues," and to not use it.

        So I changed it to fetchrow_hashref (which is the version I normally used, anyway). I did the copy/paste routine with the code I was using until I figured out what it was really doing.

        Anyway, what I discovered is that:

        my $sth2 = $dbh->prepare("SHOW FULL COLUMNS IN ?") or die 'pre +pare failed'; $sth2->execute($table) or die 'execute failed [' . $sth2->err +. '] [' . $sth2->errstr . ']';

        dies with a syntax error. And that:

        my $sth2 = $dbh->prepare("SHOW FULL COLUMNS IN $table") or die + 'prepare failed'; $sth2->execute() or die 'execute failed [' . $sth2->err . '] [ +' . $sth2->errstr . ']';

        does not die, but also does not return any rows of data.

        Lee Crites
        lee@critesclan.com