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.

use strict; use warnings; use LWP::UserAgent; my $f_temp = shift || 68; my $url = 'http://localhost:8080/GantrySoapService/f2c'; my $site = { action_url => $url, post_to_url => $url, target_namespace => 'http://sunflower.com/soapns', }; my $request_args = [ { temperature => [ { farenheit => $f_temp }, ] }, ]; my $request_xml = form_xml( $site, $request_args, 1 ); warn "request:\n$request_xml\n"; transact_via_xml( $site, $request_xml ); sub form_xml { my $size = shift; my $request_args = shift; my $pretty = shift; my $args = build_args( $request_args, $pretty ); return <<"EO_XML"; <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="$site->{ target_namespace }" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <soap:Body> $args </soap:Body> </soap:Envelope> EO_XML } sub build_args { # recursive my $request_args = shift; my $pretty = shift; my $depth = shift || 0; my $retval = ''; return $request_args unless ref( $request_args ) eq 'ARRAY'; # pretty printed for debugging: my $indent = ( $pretty ) ? ' ' x ( 2 * $depth ) : ''; my $nl = ( $pretty ) ? "\n" : ''; foreach my $arg ( @{ $request_args } ) { my ( $key, $values ) = %{ $arg }; if ( $values ) { my $start_tag = "$indent<tns:$key>"; my $child_output = build_args( $values, $pretty, $depth + +1 ); my $end_tag = "</tns:$key>$nl"; # now pretty print it pretty please if ( ref( $values ) eq 'ARRAY' ) { $start_tag = "$start_tag$nl"; $end_tag = "$indent$end_tag"; } $retval .= "$start_tag$child_output$end_tag"; } else { # values is undef or the empty string $retval .= "$indent<tns:$key/>$nl"; } } return $retval; } sub transact_via_xml { my ( $site, $request_xml ) = @_; # make the request my $user_agent = LWP::UserAgent->new(); $user_agent->agent( 'Sunflower/1.0' ); my $request = HTTP::Request->new( POST => $site->{ post_to_url } ); $request->content_type( 'text/xml; charset=utf-8' ); $request->content_length( length $request_xml ); $request->header( 'Host' => $site->{host} ); $request->header( 'SoapAction' => $site->{ action_url } ); $request->content( $request_xml ); my $response = $user_agent->request( $request ); warn $response->content . "\n"; }

Phil

The Gantry Web Framework Book is now available.

In reply to Re: Dynamic Language questions by philcrow
in thread Dynamic Language questions by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.