Lazy Perl Web Hacking til Sunrise
Interestingly enough (at least to me), it was a year ago Wednesday that I was sitting up, listening to the rain pound on a Pacific Northwestern roof, reviewing the disorganized state of Perl web development. Then, unlike now, grand visions of vast OO architectures, transparent caches, and a re-vamped Protest.net danced in my head. Tonight I’m just hacking a personal project because I can’t sleep.
I made my peace with Class::DBI tonight, or at least until I find something else about it that boggles, confuses, and frustrates me. It takes a real leap of faith, and a cast iron “La la la, I’m pretending its not there” outlook to switch from writing carefully hand crafted SQL, with delicate multi-table (inner | outer | left | cross | hectic) joins, to letting CDBI do its relatively naive (by design) thing. I recommend turning on the MySQL query log just to get a sense of how it CDBI works, useful while you’re still trying to understand the syntax, and to do what limited tuning is allowed through the interface. (still a novice admittedly) And then turn it off, and try to forget what you saw, helps if you’re the type to repress scarring memories. |
FormBuilder, Not Quite the Missing Link
So I’ve got Class::DBI, and Template Toolkit is a shoe in, I feel like CGI::FormBuilder is the last piece of the puzzle, to making really lazy (in the best possible sense of the word) Perl web applications. But…. ### Lets Talk Features
CGI::FormBuilder has a great set of features, a little over the top at times, but generally real solid, and easy to use, and amazing documentation. However, its object orientation is a very thin veneer over a procedural heart, and therein lies the problem. My ideal system is at once not that far off from CFB, and yet worlds away. A good Form class should
- Handle parsing of CGI variables, naturally
- Aid in rendering your form
- Have at least hooks for validation
All of which CFB does, in spades. Also
- Not try to do all the rendering for you. (see my PHP, A Few Tips)
- Allow subclassing – I want an object for each form in my application
- Allow subclasses to define complex input types like an image upload field, or a date field (3 constrained pull downs, or maybe a text field+dhtml widget). This is where CGI::FormBuilder seems to me to lose biggest not going the OO route.
- Allow form defaults to be set from objects (for example Class::Accessor aka Class::DBI objects) not just hashrefs
More on Template Integration
CGI::FormBuilder has native support for HTML::Template, and Template::Toolkit which is great. What that means in the context of CFB is it is capable of accepting a template specification as part of its render method. That leads to inside out code. (or so it seems to me) Ideally I would like to be able to pass a form object to a template and use it like so. ```