Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Mason & DBI driving me nuts

by EvanCarroll (Chaplain)
on Aug 01, 2006 at 01:07 UTC ( [id://564896]=note: print w/replies, xml ) Need Help??


in reply to Mason & DBI driving me nuts

Having developed *many* Mason, projects I can share some quick words of wisdom.

  • Mason isn't fun for *large* projects, and large is subjective, if you think of your own undertaking as large, you might want to look into a tool that lends itself to better code, ie an mvc type of tool
  • Learn the ins and outs of Mason - buy the Mason book the whole framework is a cinch to down, and get running
  • If you chose not use an ORM consider using $sth->fetchrow_hashref - for clarity when possible
  • Move the connect string out of the mason root!!! Use Apache::DBI, or when you fail to connect, Mason will stack dump w/ source (default) and spit out your pw
  • Use autocommit=>0 (dbi param, makes you $dbh->commit, and $dbh->rollback - the right way)
  • Make $dbh a PerlGlobal, consider another PerlGlobal ($s) for the session, I also use one more, ($u for the user), it is silly to pass these around to comps or to reinvent the wheel on every invocation - Every modern framework, agrees in putting these into a global (globals are declared with PerlGlobal, and NOT localized/initialized anywhere in your code, only set to different variables)

If you plan on doing web development, you will probably move away from Mason at some point, MVC really is an incredibly better way to design. I should have my session code, and root autohandlers on PM if I don't and you want that code, (my mason based framework I used for many years, you can have it)



Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^2: Mason & DBI driving me nuts
by doom (Deacon) on Aug 01, 2006 at 02:55 UTC
    Can you explain what you mean by an "MVC"? Just list a few examples.

    Myself, I would say that Mason is one way of implementing the model-view separation.

    (My suspicion is that you're talking about web development frameworks based on object-relational mappers like Class::DBI, in which case, I disagree strongly with your claim that they're the right way to develop "large" projects. They may be quick, they may be fun, but scale, they do not.)

      MVC is an all around more rigidly structured way of handling the web, it tends to yield better code on the whole, while being easier to divvy out amonst a team. It is more so maintainable and scalable.

      You have three fine divides, a model - interacts with the database (makes the data accessible in your language of choice), a controller which can access a model and holds all of your programming logic, and a view which simply reads from the context variable - catalyst's stash, rail's flash/other misc custom globals, etc.

      • More than one medium can access the model, the interface to the db in perl, Class::DBI, DBIx::Class custom DBI modules etc, in our implementation, the models are recycled and I use the same modules when inserting data with web crawlers, that i do when users add the data themselves.
      • The controller is often kind of like a server side http/rpc, and can be largely reused, http://foobar.com/1/2 will in most implementations dispatch to the function '1', the arg '2', in Catalyst you can form this 10900498084 different ways, you could in the path '1/2/3/4', send the function 1, the value 2, the function 3 the value 4, etc, these functions are written in the controller logic
      • view is any of the many template languages available to what ever lang you pick. TT, embperl, etc these only deal with presentation logic.

      The best Mason users, found on the mailing lists, will highlight these points in their methodologies, which largely mimic MVC now too. they often put their model functions in modules, isolated from the .mas files. A dhandler in mason is easily abstracted to be a controller, and the autohandler and seamless calling chain are the powerhouse of the language. If you start doing this too, and then you pick up a true MVC framework, you might come to view Mason as less developed -- I have.



      Evan Carroll
      www.EvanCarroll.com
        Okay, well as I suspected, we have a terminological difference going here. You talk about "using an MVC", but I think of MVC as a design pattern, not a category of software. Further, it's somewhat confusing to talk about an MVC as opposed to Mason, because Mason can -- as you admit here -- be used to implement the MVC pattern. And that's pretty clearly the recommended usage in the Mason world: Also, as I suspected, when you talk about "a true MVC framework", you're talking about the current fad for what I would call web application frameworks, all of which (to my knowledge) use some sort of object-relational mapper, (e.g. Class::DBI). The key feature of these things seems to be that they sacrifice database design for the sake of object design, which while this may speed up development it strikes me as being exactly backwards as far as performance is concerned.

        And so we come to your closing shot: "pick up a true MVC framework, you might come to view Mason as less developed -- I have." May I inquire, in what way you find it "less developed"?

Re^2: Mason & DBI driving me nuts
by johnnywang (Priest) on Aug 01, 2006 at 05:25 UTC
    I think you meant frameworks like CGI::Application, Maple, Catalyst, etc. That's what I usually use. The parallel distinction in the java world is jsp vs. frameworks like Struts. I only use Mason occasionally, but was told that Amazon mainly use Mason, it then must be "good enough"?
      Amazon doesn't use Mason externally, they use it internally to "prototype." Many books have clairfied this.


      Evan Carroll
      www.EvanCarroll.com
        Amazon doesn't use Mason externally, they use it internally to "prototype." Many books have clairfied this.

        So it shouldn't be too hard to name one of them, right?

        I can't find this anywhere on the web. As of a few years ago the story was that Amazon was using Mason quite a bit, and had plans to use it even more...

        A number of sites use Mason: MasonPoweredSites

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-16 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found