Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Avoiding loading modules

by derby (Abbot)
on May 04, 2007 at 16:38 UTC ( [id://613614]=note: print w/replies, xml ) Need Help??


in reply to Avoiding loading modules

Through judicious use of require and import you can shift the burden of module loads from compile time to run time ... but ... a large number of 'use' directives is a huge red flag that your app is becoming a big ball of mud. I'd look into ways of redo-ing the app so there's not a huge number of use directives (or a huge number that impacts load time). And before I shifted to the require/import method, I would probably use Autoloader (I like seeing the use statements at the top of the file).

-derby

Replies are listed 'Best First'.
Re^2: Avoiding loading modules
by wfsp (Abbot) on May 05, 2007 at 08:14 UTC
    ...a large number of 'use' directives is a huge red flag... I'd look into ways of redo-ing the app
    Could you expand on that? I often end up with "a large number of 'use' directives" to, amongst other things, _avoid_ a big ball of mud. :-)

    How many is large? How would you go about "redo-ing the app"?

    I, too, "like seeing the use statements at the top of the file". But perhaps for the wrong reasons?

      It would depend on the type of app but for me, it's mainly web apps. If one of my web apps get's huge, I take a hard look at the namespace (http://www.foo.com/webapp) and see if I can break it out into parts. For example, for a typical CRUD database app, I may do:

      • http://www.foo.com/webapp/create
      • http://www.foo.com/webapp/retrieve
      • http://www.foo.com/webapp/update
      • http://www.foo.com/webapp/delete
      and then instead of all the logic (model,view,controller) being in one big-old-module (webapp), I would transition as much as I could to new modules which hold the logic for each piece of the app (with appropriate commonality in a webapp superclass). So the object hierarchy may look something like this in the file system:
      • /path/to/foo/webapp
        • Controller.pm
        • Model.pm
        • View.pm
        • create
          • Controller.pm
          • Model.pm
          • View.pm
        • retrieve
          • Controller.pm
          • Model.pm
          • View.pm
        • update
          • Controller.pm
          • Model.pm
          • View.pm
        • delete
          • Controller.pm
          • Model.pm
          • View.pm

        As for when to do this -- I cannot say. For me it's more a comfort level decision. I tend to apply cohesion and coupling principles at the module level - when the module is doing too many things and I cannot reasonably reuse it, then I break it down.

        -derby

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://613614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found