Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Dynamic Language questions

by talexb (Chancellor)
on May 14, 2007 at 03:08 UTC ( [id://615215]=perlquestion: print w/replies, xml ) Need Help??

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

I'm posting this on behalf of Richard Dice, fellow Toronto Perlmonger and Perl Foundation guy. He's responding to a study on Dynamic Languages, and needs some input from the minds at Perlmonks.

So, no, this is *not* homework. Here are the questions:

    • Render a simple Web page containing text, data, and graphics.
    • Can the language render a simple Web page containing text, data, and graphics from a prespecified Wireframe design?
    • Invoke a simple Web service and display the results.
    • Can the language invoke a simple Web service, format and display the results?
    • Create a simple form for data submission with fields and drop down selects and a submit button. A sample wireframe will be provided with at least one field that should be validated.
    • Can the language create a simple form that implements a sample design?

Richard has completed the first example, and his result is available here. it's actually two versions, the first is a fully documented one, and the second is a striped down version with the same functionality. If anyone wants to supply their own solution, go right ahead.

Richard concludes, In terms of completion of the work, I'd like to receive a tarball with source code, HTML files, etc. Also, if the author can provide a URL at which the working code example is hosted, please do!

I'll be passing along the URL to this post to Richard, and you can also reach him directly at his pobox.com address rdice.

Update: I've added links to the two CGIs on the page here.

Update 2: This is frustrating .. pressing 'Submit' on the forms generates the old Internal Server Error, but I don't have time right now to solve the problem. Sorry about that.

Update 3: OK, it turns out that pair Networks had version 3.12 of Data::FormValidator installed -- that explained the Internal Server Error messages. I installed 4.50 of the same module, added a use lib statement in the CGIs, and now everything works fine. Thanks for your patience.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re: Dynamic Language questions
by Dice (Beadle) on May 14, 2007 at 11:57 UTC
    Hi everyone, Richard here...

    I asked talexb to post this because his PerlMonks-foo is strong, so he'd know where to categorize this strange request.

    Basically, I'm just drowning in work trying to answer the other 100-ish questions in the survey in time for this coming Friday (when Forrester would like the replies) so I decided that the "I'll do everything myself!" strategy just wasn't going to work. I spent a lot of time on Sunday trying to figure out who I could ask to help out with what questions and emailing them to get in touch. For these 3 questions I thought, hey, PerlMonks! People here seem to like code challenges. (That's something that I don't think came through strongly enough from Alex's posting. What is actually being asked for in the survey is code examples that show the language being used to do the question/task given.)

    On a personal note, I'd be really interested in seeing alternative code to what I made. (This is the .tar.gz that Alex linked to.) I think it's a pretty clean, simple and concise reply to the question but it also seems like it would be pretty abstract to someone who doesn't live and breathe Perl and the CPAN.

    While I'm thinking about it, does anyone out there have experience and knowledge with Web Services Standards? There are a chunk of questions on this in the survey and I'm not sure right now who I can turn to for help. These are the topics - Core Web Services, Web Service Security, Web Service Management, Registry and Metadata, Process and Delivery Control, Transaction and Packaging. These are paragraph-sized essay questions. Someone who knows this stuff could probably put it all to bed in 10 minutes. If you know this stuff and think you could spare a bit of time to help out, please get in touch. (Alex slipped my email address in to the posting. How tricky of him!)

    Regarding the two replies I've seen so far, on the question of "wireframes" - no, it's not a product. It's just their terminology for "inactive HTML mockup." You can click on the links that Alex gave to see screenshot images of the "wireframes." What they're asking for is an implementation of code that powers this. My own code sample actually takes care of item #3 in Alex's list. (Not the "first example" as Alex called it in his posting.)

    About the survey -- Forrester Research got in touch with The Perl Foundation about 2 weeks ago, asking for us to participate in a survey they are doing regarding "Dynamic Languages." The languages that are being included in the survey are: Perl, Python, PHP, Ruby, Javascript and JScript. (Yes, I know they aren't all in the "same space." It's their survey and they'll have to make that clear using their own techniques.) The survey involves about 100 questions, a handful of submitted code samples, and a collection of telephone interviews, and it has been eating my brain quite handily. But I think it's important for TPF to participate or else Perl just won't be represented in the survey. The consumers of the research are going to be Fortune 500-type companies, their CIOs, VPs of IT, etc. It's a really good opportunity to show the applicability and relevance of Perl to enterprise computing.

    Cheers,
    Richard

Re: Dynamic Language questions
by philcrow (Priest) on May 14, 2007 at 13:11 UTC
    For number one, you might also point out that there are many live sites on the web generate something like the example, including this site and slashdot. I would also point out that we have templating systems that make redesigns easy.

    For number three, we use a Perl framework for tasks like that. There are several of those, ours is http://usegantry.org available from cpan as Gantry. Catalyst is another fine choice. Use of a framework means the code samples would be quite involved. If you are writing a little self contained script, you should probably use Data::FormValidator for the form validation.

    For number two, I have a small document style SOAP client to run from the command line. It is self contained, except for using LWP::UserAgent for actual tcp traffic. I just dumps its results, but you could combine its approach with the answer to Number 1 above to render the result in pretty form.

    Phil

    The Gantry Web Framework Book is now available.
      Thanks a lot for the code sample!

      Regarding example 1, yes, I can point to plenty of Perl sites that do what they're asking for in the wireframe example. But, while I can hand them the Slash sourcecode, it would be overkill, boggle their brains, and make them think "it would be so much easier to do this in PHP." What would be useful here is a *minimal* example, much like you suggest for example #3.

      Regarding example #3, yes, I used Data::FormValidator, HTML::Template and HTML::FillInForm. (My own code is available for download from the links talexb provided in his original post.) I contemplated CGI::Application for a minute but discarded it as being overkill for the application at hand. But who knows, maybe HTML::Embperl would be the right way to go in this situation. I haven't coded like that in a long time but it might give a useful point of comparison to the other languages in the survey.

      Cheers,
      Richard

      Phil,

      Could you describe to me the web service this accesses and what it does with it? Maybe show me an text-capture of a user interactive session with it?

      Thanks,
      Richard

        Here is the output from running the above script:
        perl soapclient 98.6
        Produces request:
        <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://sunflower.com/soapns" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <soap:Body> <tns:temperature> <tns:farenheit>98.6</tns:farenheit> </tns:temperature> </soap:Body> </soap:Envelope>
        When the server has done its bit, the script prints the response:
        <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <soap:Body> <GantrySoapServiceResponse xmlns="http://usegantry.org/soapservice"> <currentUTCTime>2007-05-15T12:08:18Z</currentUTCTime> <celcius>37</celcius> </GantrySoapServiceResponse> </soap:Body> </soap:Envelope>
        The names of the parameters and their allowed types are usually governed by a WSDL file (perhaps that expands to Web Service Description Language, but I'm not sure of the achronymn).

        Note well that you can convert the script to contact any document style service on the web by changing the URLs and providing the correct argument structure. For instance, I started this test against a public web service. I used:

        my $site = { action_url => 'http://in2test.lsi.uniovi.es/sqlmutationws/getMutantsCompress +ed', post_to_url => 'http://in2test.lsi.uniovi.es/sqlmutationws/SQLMutationWS.asmx +', target_namespace => 'http://in2test.lsi.uniovi.es/sqlmutationws', };
        and
        my $request_args = [ { getMutantsCompressed => [ { sql => 'select * from table1' }, { schema => undef }, { options => undef }, ] }, ];
        If you make those changes, and the public service is still up, you should get a result from anywhere on the net.

        In case it might help with this question or some other question you didn't post, here is the code from the Gantry samples which serves the original script:

        If you have Gantry installed, that's a complete server module. All you need to do is mount it with mod_perl or some other server approach.

        Thanks for taking the time to respond to the survey for all of us.

        Phil

        The Gantry Web Framework Book is now available.
Re: Dynamic Language questions
by Rhandom (Curate) on May 14, 2007 at 15:52 UTC
    Here is another sample using CGI::Ex::App. It behaves identical to the examples the OP provided in the tarbar. There is very little actual code to be written - and if we wanted to take it further we could move the validation and stick it out in a yaml file, and we could take the template and stick it out in a .html template file. Then the CGI would be really short. It can be viewed at http://iterpret.com/cgi-bin/perlmonks_615215.pl.
    #!/usr/bin/perl use warnings; use strict; use base qw(CGI::Ex::App); __PACKAGE__->navigate; sub main_hash_validation { return { 'group no_alert' => 1, 'group no_confirm' => 1, member_type => {required => 1}, member_name => {required => 1}, member_address => {required => 1}, company_size => {required => 1}, member_phone => { required => 1, match => 'm/^\(\d{3}\) \d{3}\-\d{4}$/', match_error => 'Please type the phone number in (888) 555- +1234 format', }, }; }; sub main_finalize { my $self = shift; $self->add_to_swap(it_validates => 1); return 0; } sub main_file_print { return \ <<'DOC'; <html> <style>span {color:red}</style> <head> <title>FormWireframe</title> </head> <body> <h2>Simple Form Wireframe</h2> <blockquote> <form method=post name=[% form_name %]> <table> <tr> <td align=left valign=top colspan=2> <h3>Add/edit member</h3> </td> </tr> <tr> <td align=left valign=top colspan=2> <h4><font color=red>*required fields</font></h4> </td> </tr> <tr> <td align=left valign=top> Member Type* </td> <td align=left valign=top> <input type=radio name=member_type value=organization> Organization <input type=radio name=member_type value=individual> Individual <span id=member_type_error>[% member_type_error %]</span> </td> </tr> <tr> <td align=left valign=top> Member Name* </td> <td align=left valign=top> <input type=text size=30 name=member_name> <span id=member_name_error> +[% member_name_error %]</span> </td> </tr> <tr> <td align=left valign=top> Member Address* </td> <td align=left valign=top> <textarea name=member_address rows=4 cols=30></textarea> <span id=memb +er_address_error>[% member_address_error %]</span> </td> </tr> <tr> <td align=left valign=top> Phone* </td> <td align=left valign=top> <input type=text size=20 name=member_phone> <span id=member_phone_erro +r>[% member_phone_error %]</span> </td> </tr> <tr> <td align=left valign=top> Company Size* </td> <td align=left valign=top> <select name=company_size> <option></option> <option>Over 20,000</option> <option>Over 10,000</option> <option>Over 5,000</option> <option>Over 1,000</option> <option>Under 1,000</option> </select> <span id=company_size_error>[% company_size_error %]</span> </td> </tr> <tr> <td align=center valign=top colspan=2> <input type=submit name=submit value=Submit> </td> </tr> </table> </form> [% js_validation %] </blockquote> [% IF it_validates %] <h2>Congrats! This form validates completely!</h2> [% END %] <a href=[% script_name %]/source>Source for this file</a> | <a href=ht +tp://perlmonks.org/?node_id=615215>Perlmonk node 615215</a> </body> </html> DOC } sub source_run_step { shift->cgix->print_content_type('text/plain'); open(my $fh, "<", __FILE__) || die; print <$fh>; return 1; }


    my @a=qw(random brilliant braindead); print $a[rand(@a)];
Re: Dynamic Language questions
by mattr (Curate) on May 15, 2007 at 08:41 UTC
    Hi. The answers are yes to all the questions. A zipfile and demo site are available below. The zip is code for the admin portal which you cannot see but it is "real" code and satisfies a couple of your requests.

    Based on my experience in a project I am delivering this week, and the recent YAPC::Asia conference, I'd say the state of the art is to use Catalyst. Though all the following elements can be used separately and combined with other modules in CGI too:

    Oh and some people like a different framework, Jifty which I don't know well enough to mention. However the "What's Cool About Jifty" part of its docs suggest it might even be easier than Catalyst to use! Hmmmm. It has form based dispatch so you don't have to write your own forms. In FormBuilder you write a spec for the form and how each field is validate in a configuration file and then write your backend code. I wonder if Jifty is even easier..?

    There are other frameworks too.. and you can roll your own. CGI::Application and CGI.pm was my friend until I left for Catalyst. I used HTML::Widget for forms for a little bit but switched to FormBuilder (at least until the H::W team finishes their new module). Some people like HTML::Template (which I used for a while before TT) or HTML::Mason for templates instead.

    Wireframes, I've been doing for years with Perl. Used Visio for a while, now use OpenOffice. You can actually put HTML created through autoprototyping wireframe systems like Azure (or OpenOffice - save as HTML) into the catalyst templates folder and they will just work, but I prefer writing the HTML myself to keep it all clean and sane. Lets you incrementally add and test functionalisty. Wonderful!

    I like Template::Toolkit for the way it lets you add code (their macro language as well as perl code though that is overkill - and I haven't used it but it ought to cover the Embperl case you mentioned) and you can just hand it a DBIx::Class resultset from a database search and you can then add object oriented tags to the templat for where you want fields to show up, looping around them for a list. (Try the search function in the demo below for example).

    Web service, yes and it can even run on a separate server from your static content or serve static content if you want, you can write your own demons, use SOAP and other formats, etc.

    I think the key is understanding that there is nothing stopping the language from doing any of these things, and it has a very strong public module repository with many of the hard things already done, polished, tested and integrated.

    If you want a sample, point your browser to my beta site which is running right now. It includes creation of a customer portal for account management and automatic account creation based on signup form, plus automatic fulfillment by receiving Instant Payment Notifications from PayPal. If you want to use it as a demo to someone email me at telebody.net at mattr (backwards). This system is based on MySQL. I can give you a login if you want to see the customer portal, which includes a sales catalog with Buy Now buttons for advertising packages, or I can send a screenshot.

    Also as demonstrated in a video on the YAPC ::Asia videos site, you can build a REST style interface to data and then easily render it out as HTML, JSON, XML, etc.

    Catalyst has many, many modules used in it so it is easiest if you are root on linux. (not required though). And this is for a client so I can't give you a tarball. I can give you a copy of part of a screen rendering template and a formbuilder spec file. It's a pretty comprehensive site (like a mini-yahoo for Wisconsin cities) but willing to show you code for parts you need. The PayPal functionality for example might cover the Transaction topic you (Richard) mention.

    I've assembled part of a catalyst system based on subroutines from my production code, here (zipfile). It won't run as-is since there is no database behind it, but it includes all the files and subroutines I think to run the "list customers" and "edit a package" functions in the admin portal of a real site. It doesn't include the PayPal code though I can supply if you require it. It does include templates (satisfying the wireframe request) using templates with embedded macro code broken into subtemplates, and a submission form based on FormBuilder with a separate spec file. There is no need to write html for the form and FormBuilder handles validation both in Perl as well as in Javascript (displaying an error on invalid input). I will be removing the zip file after a while so if you need it please take a copy and tell me if you do. Thanks.

    Matt

    Updated the zip file by adding the scripts folder and arranging Controller and View folders correctly (code is mainly in Admin.pm). It might even work if you run scripts/catmgr_server.pl and point your browser at localhost:3000/admin/admin_package_edit which would be a formbuilder form.

Re: Dynamic Language questions
by Anonymous Monk on May 14, 2007 at 04:47 UTC
    The answer to all 3 questions is YES.
Re: Dynamic Language questions
by DrHyde (Prior) on May 14, 2007 at 09:14 UTC
    Seeing that you capitalised Wireframe, I assume that it is a particular product. In which case, the answer to all three questions is "I've never heard of it, so I don't care".

      And yet, you just had to reply and let people know that you don't care.

      website wireframe, for anyone who's curious.

      Valid point -- I should not have capitalized wireframe. What I really meant was a mockup, like this.

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

        In that case, if I understand "wireframe" correctly, the answer to your first and third questions is "only with great difficulty, and the results will probably suck", which is the same answer as you'd get for any other programming language. That's because computers suck at understanding pictures.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://615215]
Approved by Popcorn Dave
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-28 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found