So I started building my own web app framework on top of mod_perl with jQuery Mobile for my front end. It was mostly done as an exercise for fun and learning. It's far enough along where I can make some pretty sophisticated forms with a few lines of code. It's far from complete but I feel comfortable with it because I wrote it myself and I know exactly how it works. I know how to get and save data to the database. If I kept going, I could improve upon it and add more and more capabilities and efficiencies.
Of course, it's not 2005 anymore. Many frameworks exists. Rolling your own is probably crazy...or is it?
I just downloaded and installed Dancer2. I got the sample app running. I spent about an hour looking it over. Here's some sample code from the tutorial:
<h2>Login</h2> [% IF err %]<p class=error><strong>Error:</strong> [% err %][% END %] <form actione="[\% processor_url %]" method=post> <dl> <dt>Name: <dd><input type=text name=name> <dt>Another field: <dd><input type=text name=text> <dd><input type=submit value=Submit> </dl> </form>
And with that sample code, I am less than impressed with what I see. I don't want to have to write what looks essentially like HTML with embedded Perl. I want to write high level code that generates as much HTML and javascript logic for me as possible.
Now, please compare the above with a sample from my code which generates this form:
sub handler { my $r = shift; my $html = MyApache2::AppPage->new({reqrec => $r, title => 'Upload F +ile'}); $html->add_header('header', { fixed => 1 }); $html->add_pages([ { title => 'Upload file', id => 'upload_file', ca +che => 1 }, ]); my $navbar = &MyApache2::Admin::Upload::generate_nav($html); $html->add_navbar($navbar); $html->add_content('upload_file', 'h1', 'Upload voter data file'); $html->add_content('upload_file', 'p', 'You can upload voter data he +re. Upload the file and choose the type of data you are uploading. There are two kinds of data you can upload +. One is a list of registered voters an d associated information called a <b>"Voter registration file."</b> Th +e other is a list of voters who partici pated in a particular election called a <b>"Voter activity file."</b>' +); my $form = $html->create_comp('form', 'ul_form', {method => 'post', +enctype => "multipart/form-data"}); $form->add_element('file', 'file_upload_field', {required => 1, allowed_exts => ['c +sv'], label => 'File (csv + format only)'}); $form->add_element('selectmenu', 'file_type', { label => 'Data file type', options => ['Voter registration file', 'Voter activity file'], required => 1, options_label => 'Select voter data type...', unhide => {'activity_data' => ['Voter activity file'], 'reg_data' => ['Voter registration file'], }, }); my $reg_fields = $form->add_element('html', 'reg_data', { hide => 1, + show_container => 1}); $form->add_element($reg_fields, 'textfield', 'date', { label => 'Date data was created', subtype => 'date', required => 1 }); my $act_fields = $form->add_element('html', 'activity_data', { hide +=> 1, show_container => 1 }); $form->add_element($act_fields, 'textfield', 'election_date', { subtype => 'date', label => 'Election Date', required => 1 }); $form->add_element($act_fields, 'textfield', 'election_desc', {label => 'Description of election', required => 1 }); $html->add_content('upload_file', $form); $html->generate; return Apache2::Const::OK; }
This simple amount of code results in a page that looks like this.. And so with a couple of off-the-shelf javascript libraries and my own HTML generation engine, I can crank out a pretty sophisticated form with fancy validation and javascript enhancements pretty easily. And, with my system, I can code in Perl, not in some pseudo HTML.
So, to get to my question, am I going to be able to crank out some sophisticated stuff with a few lines of code with Dancer? Is it going to limit my ability to automate the generation of HTML as much as possible? What, exactly, does Dancer buy me?
I'm pretty sure Dancer2 is more than likely the superior approach because people a lot smarter than me are using it. I'll admit I'm ignorant. But, still, I'm just not seeing the advantage right now. Can someone please set me straight?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |