Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

malte (1708)

  (email not shown publicly)

Working on Joose JavaScript meta system (Blog) [] and blok [], a web based application for collaborative ui prototyping.

Journal of malte (1708)

Monday August 08, 2005
06:18 AM

HTML::Element interface

[ #26177 ]

I have written a class with the following properties:

  • The new method creates an instance of HTML::Element and stores it away.
  • Method calls that can be handled by HTML::Element are delegated to this object, but they all return self.
  • All other method names are interpreted as html-attribute accessors.
  • Stringification is overloaded to as_HTML

That way you can write: HTML::Element::Whatever->new('input')->name("hallo")->value("welt")->size(10) and you get the HTML source for the appropriate input element.

This allows for some really concise generation of HTML.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • That's a great interface for $object to HTML generation. I kind of wish SQL::Translater had the same thing:
    my $table = SQL::Translator::Schema::Table->new('mytable');
    $table->column('id')->type('var char')->size('36')->default('foo');
    *adds that to mental list of things to make...*
  • What's it called, and when are you putting it on CPAN? :-)
  • To be honest, I don’t think that’s particularly a good interface. Passing a hashref for attributes is both more obvious as well as more concise, syntax-wise.

    I’m also never sure whether to like method chaining in general or not. It’s a kludge for Perl5; fortunately we won’t need it in Perl6.