Bill Moseley writes:
> Anyone have links to examples of MVC Perl code (mostly controller code)
> that does a good job of M and C separation, and good ways to propagate
> errors back to the C?  

I humbly (do believe that ;-) submit http://petshop.bivio.biz
Every page contains the control logic which is dynamically parsed from
the Task configuration.  Here's an example:

http://petshop.bivio.biz/pub/products?p=BIRDS

The configuration for this task is:

        [qw(
            PRODUCTS
            500
            GENERAL
            ANYBODY
            Model.ProductList->execute_load_all_with_query
            View.products
        )],

The name of the task which is used for all internal linkages is
PRODUCTS.  The number is a convenience for FormContext, i.e. our
"closure" mechanism for holding state between HTTP forms.

The "realm" is GENERAL, i.e. there is no particular owner.  You might
have a USER realm or CLUB (group) realm, which have owners.

Permission bit is ANYBODY.  You can have multiple permission bits,
e.g. DATA_WRITE&DATA_READ.

The rest of the list are "items" which are executed serially.  The
syntax is <ClassMap>.<Class>.  A class map allows you to configure
where your models are loaded from.

Here's another example:

        [qw(
            LOGIN
            517
            GENERAL
            ANYBODY
            Action.UserLogout
            Model.UserLoginForm
            View.login
            next=CART
            MISSING_COOKIES=MISSING_COOKIES
        )],

The '=' elements (which is not "strictly" perl, but hey, we all have
are inconsistencies ;-) map events to other tasks.  For example, if
you get a MISSING_COOKIES exception you go to the MISSING_COOKIES
task.  next=CART says that the next task on an OK on the form is the
CART task.

All tasks can be found in
http://petshop.bivio.biz/src?s=Bivio::PetShop::Agent::TaskId

This is all you need to know about the controller if you use bOP.  You
list your tasks and bOP's Agent does the rest.  BTW, the tasks might
be executed via e-mail or HTTP or the command line.  The controller
abstracts this away, too.  (We actually removed our Bivio::Agent::Mail
implementation, because it made more sense to implement everything via
Apache instead of custom servers.)

The interface for Views, Actions, and Models is called "execute".
You'll be passed a Bivio::Agent::Request object which holds the
context for the transaction.

Rob




Reply via email to