I tend to make "mini MVC's" with Mason. I find that overabstraction leads to the exact inverse of what you are trying to avoid -- redundant code. And that inverse is a God object that tries to do everything for everybody. So, what i do from time to time is create a top level component that handles CRUD, so my update sub would first call a custom validation sub located in the same package. I set up a messaging system so that if a user enter invalid data, they see the same form with their error messages so they may correct and resubmit. I determine what the "response page" is by calling the proper component. If they entered valid data, that component is the list view. If not, that component is the add_update view again.

This method has worked very well for -- giving me enough abstraction to make laborious tasks more fun while not being too rigid that i have to readdress my design over and over. Here is the update() method of one of these "objects" :

sub update { my %args = @_; my @messages = (); my @errors = validate_args( %args ); if (@errors) { # package the errors up as error messages @messages = map {{ class => 'error', data => $_ }} @errors; # override landing page back to update so user can fix errors # $comp is set to 'list' prior to this method call $comp = 'update'; } else { my $sth = $dbh->prepare(' UPDATE thingy SET foo = ?, bar = ? WHERE id = 1 '); $sth->execute( $args{foo}, $args{bar}, ); push( @messages, { class => 'message', data => 'Thingy successfully updated.' } ); } return @messages; }

This method is called by a dispatcher which then determines what to fetch:

$m->comp( "comps/thingy/$comp.md", messages => \@messages, %ARGS );
For every CRUD method in the "object" there is a corresponding Mason component that acts as the "template." I try to treat these component like HTML::Template templates -- only variable substitutions, conditions and loops -- but i will throw in display code from time to time like TT would allow me to do.

I hope this adds to the conversation -- I kinda missed what the point was. :/

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: CGI::Prototype criticism 1 - cannot use POST-redirect-GET paradigm by jeffa
in thread CGI::Prototype criticism 1 - cannot use POST-redirect-GET paradigm by metaperl

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.