You probably already have something along these lines–

It’s a good pattern because it gives you DB code that is not tied to your web app but is easily usable from your web app with very little code and extremely flexible configuration. So, repeating this for other data-oriented parts of the application is usually the way to go. Something like–

Your setup would look approximately like–

package MyApp::ForeignSource::SOAP; # Some object system… Moose/Mouse/Class::Accessor use SOAP::Lite; # Collection of methods and attributes for running SOAP requests # and returning the data in nice perl structures or with iterators # and helpers like Data::Page. 1;
package MyApp::FSS; use parent "Catalyst::Model::Adaptor"; __PACKAGE__->config( class => "MyApp::ForeignSource::SOAP" ); # If the arguments to MyApp::ForeignSource::SOAP # are a hash ref, you’re probably done. 1;
--- # myapp.yml Model::FSS: args: service: http://soap.example.org/srvc.wsdl et: cetera

Contrived controller example with made up methods/data/flow.

package MyApp::Controller::SomeClass; use Moose; use namespace::autoclean; BEGIN { extends "Catalyst::Controller" } sub index :Path :Args(0) { my ( $self, $c ) = @_; my $pref = $c->user->search_related("prefs", {type => "soap"}); my $fss = $c->model("FSS"); my $stuff = $fss->call("fooBar", $fss->data->name("key")->value($p +ref->value)); die $stuff->faultstring if $stuff->fault; $c->stash( result => $stuff->result ); } __PACKAGE__->meta->make_immutable; 1;

The arguments, methods, object design (Moose is very good at delegation so I’d recommend it for your MyApp::ForeignSource::SOAP class) and such will be details of your particular implementation but that skeleton is The Right Way® in Catalyst. Don’t forget to write tests! If you can write them against your current Flex code, so much the better.

Reading list

Sidenote: some Catalyst devs advocate putting the MVC components in a Web subdir: e.g., MyApp::Web::Controller::Root. I don’t and haven’t had a problem keeping disparate parts in parallel but it’s certainly a sane and clear division.


In reply to Re: I need wisdom on structuring procedural code in Catalyst by Your Mother
in thread I need wisdom on structuring procedural code in Catalyst by miguelele

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.