I'll write one at the top of my head. It's really silly tho...
package HTMLTag; sub new { bless { tag => '', mainval => '', subval => '' },$_[0]; } sub tag { my $self = shift; $self->{tag} = $_[0] if $_[0]; # set if applicable $self->{tag}; # return } sub val { my $self = shift; $self->{mainval} = $_[0] if $_[0]; $self->{mainval}; } sub extra { my $self = shift; $self->{subval} = $_[0] if $_[0]; $self->{subval}; } sub str { my $self = shift; my $ret = join($self->{tag},"<",">"); if ($self->{tag} eq 'a'){ $ret .= join(""," href='",$self->{mainval},">",$self->{subval} +,"</a>"); } elsif ($self->{tag} eq 'img'){ $ret .= join(""," src='",$self->{mainval},"' alt='",$self->{su +bval},"'>"); # not sure about actual HTML correctness... i forget } } 1; # keep Ryszard happy ;-)
And an example implementing:
use HTMLTag; my $link = new HTMLTag; $link->tag('a'); $link->val('img.jpg'); $link->extra('A picture of my dog'); my $image = new HTMLTag; $image->tag('img'); $image->val('img2.jpg'); $image->extra('My cat'); print $link->str(),$image->str();

Ofcourse, the beauty of objects is complexity hidden behind a simple look. That's why it's hard to find simple ones...

-nuffin
zz zZ Z Z #!perl

In reply to Re: Real life OO examples by nothingmuch
in thread Real life OO examples by kbeen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.