Alexandr Efimov wrote:
> 
> Hello, all!
> 
> We have a 4 year experience in developing web sites
> for our customers. Most of these web sites must present
> information stored in some relational database
> (MySQL or Oracle), and we create a special web interface
> for managing the data stored in the database.
> We cannot use standard modules like DB::Editor,
> because we need to provide a simple and easy-to-use
> interface for end user.
> 
> We used to create such interface using Apache::ASP,
> but that was incovenient because we could not
> reuse code for different projects, and it required a programmer
> and a usability specialist to work togather on such interface

You ever look at XMLSubs in Apache::ASP?  It should
promote code reuse like you are going for.  You just
need to install your XMLSubs module in each of your
projects.  

Also, if you decomp much of your generic application 
logic into some real object, you can init this object, 
say $App, in Script_OnStart, and have it available in 
all scripts just like $Server, $Session, etc.

use vars qw($App $Form);
sub Script_OnStart {
   my $dbh = DBI->connect(...);
   $App = My::App->new(dbh => $dbh, ...);
   $Form = $Request->Form;
}

The you can reference $App in all scripts & includes,
just like

 <%= $App->print_something %>

since all scripts & includes are compiled into the same
package as global.asa.

For support of the code you mentioned like:

 <edit sql="update banned_ip set ip=? where ip=?" params="ip old_ip">
 <delete sql="delete from musica.banned where banned_ip = ?" params="old_ip">
 <add sql="insert into musica.banned (banned_ip) values (?)" params="ip">
 
You can define

  PerlSetVar XMLSubsMatch edit|delete|add 

Then in global.asa, you can define you subs like so:

# assuming edit() represents a widget & db function  
sub edit {
  my($args, $html) = @_;
  my @params = split(/\s+/, $args->{params});
  if($Form->{'edit'}) {
    $App->{dbh}->do("$args->{sql"}, undef, map { $Form->{$_} } @params);
  }
  print "<input type=submit name=edit value=Edit>";
}

Because these XMLSubs don't have their own namespace you 
would not be able to decomp them into their own perl package,
but you could put them in a perl module without a package,
and then use/require/do them from global.asa to import.
I only suggest this for code reuse between projects.
You could also have them in a package, and them import
the functions, but you might have to reference vars like
$main::App, which you would have to init in global.asa.

Its very easy to not use good coding practice with 
Apache::ASP, but you can use like any other full embedded perl
environment for good code reuse.

One more thing ... XMLSubs are limited to parsing out only
the XML attributes & body, so things like FOREACH are harder
to implement, however a recent feature makes it possible,
as you can now $Response->Include() scripts data on the fly,
not just file names, so:

XMLSubs FOREACH|rows|row|inp

  <rows name=myrows action=fetch sql="select banned_ip from banned order by banned_ip">
...
  <FOREACH c=myrows>
  <row>
  <inp name="ip" type="text" value=c.banned_ip size="15">
  <inp name="old_ip" type="hidden" value=c.banned_ip>
  </row>
  </FOREACH>

sub rows { 
  my $args = shift;
  my @rows;
  my $sth = $App->{dbh}->prepare($args->{sql});
  while(my $row = $sth->fetchrow_hashref) { push(@rows, $row); }
  $App->{rows}{$args->{name}} = $rows;
}

sub FOREACH {
  my($args, $script) = @_;
  my $rows = $App->{rows}{$args->{c}};
  for my $row (@$rows) {
     $App->{currrow} = $row;
     $Response->Include(\$script);
  }
}

sub inp { 
  my $args = shift;
  my $row = $App->{currrow};
  print "<input name=$args->{name} value=$row->{$args->{name}} ...";
}  

Just as example of how you might achieve what you are going
for with Apache::ASP.  I know you used it before, but the
application environment has grown considerably over time, 
now in its 4th year of development.

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

Reply via email to