Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
"be consistent"
 
PerlMonks  

CGI::App dynamic runmodes/modules

by Ryszard (Priest)
on Oct 15, 2006 at 17:26 UTC ( #578404=perlquestion: print w/ replies, xml ) Need Help??
Ryszard has asked for the wisdom of the Perl Monks concerning the following question:

I've got a bit of a problem with my web application and a CGI::Application framework.

let me explain a little.

I've written a module based on CGI::Application, and every other module i use inherits from it (ie when writing another module i do 'use base CGIA::Replacement'; )

My web app has "registered" users (ie users that will log in via the website, session stored in the database etc etc). Each user belongs to a group, and that group has specific attributes.

My goal is to create (from a dev/admin POV) a "My Website" framework, where i can just program another module, add it to the $path, update a database table and the content/functionality will be automatically added to the greater application.

Now (bear with me a bit while i share some detail), i've got a database table that maps a group with a feature (for example "upload file"), and (for the sake of normalisation) i have a mywebsite_feature table that maps a library to that feature.

From this setup i can dynamically pull in (at run time via require) whatever libraries are associated with the group of the user logged in. With a "special" method in the library, i can return the method(s) i would like the application to access (such as showTemplate(), or storeFile() )

what i'm having trouble with is the mechanics in accessing the dynamically added runmode.

so, in summary, what i want is a CGI::Application based module that will dynamically use other modules and dynamically add run modes based on the output of a "special" method in the dynamically loaded module.

in closing, i have two remarks:
1) i cant but help think this is quite a messy approach to doing this

and

2) (disclaimer) i've been working at this for hours now, and perhaps cant see the wood for the trees

If anyone has experience in doing this, or suggestions on how it could be done better, i would love to hear it.

Comment on CGI::App dynamic runmodes/modules
Select or Download Code
Re: CGI::App dynamic runmodes/modules
by rhesa (Vicar) on Oct 15, 2006 at 18:49 UTC
    I have to admit I don't understand the logic flow of your framework in detail, but I think what you want can be accomplished with CGI::Application::Dispatch. To make it work, you'd split up your web app into many smaller cgiapp modules, and route to them through the URL.

    For our photo gallery site, we use this approach, and it works very well. As an example, I have the following classes:

    EM::UI::Admin::Layout EM::UI::Admin::Report EM::UI::Admin::Upload
    and my dispatch table looks something like this:
    CGI::Application::Dispatch->dispatch( table => [ # admin apps '/admin' => { app => 'EM::UI::Admin', rm => 'ove +rview' }, '/admin/:app/:rm/:id?' => { prefix => 'EM::UI::Admin' }, # general public apps ':app/:rm/:id?' => { prefix => 'EM::UI::Public' }, ], );
    That way, a url like http://example.com/admin/layout/overview would get dispatched to the "overview" run mode in EM::UI::Admin::Layout.

    The advantage of this approach is that I can simply drop in a new cgiapp class with new functionality, and it will work out of the box. It also helps with maintenance, since the classes are generally fairly small, and only contain code related to a single feature.

    Some other plugins you may want to look into - in case you don't know of them yet - are:

    There are a lot more plugins, but these are the ones that help me the most in building scalable and maintainable web apps with CGI::Application.
      Cool rhesa, i'd not explored this possibility..

      The application framework i have is quite extensive taking into account session management, authorisation, authentication etc etc.

      Hopefully this is something i can build into it.. ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://578404]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-04-18 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (462 votes), past polls