This is a simplified version of a class I have.
It does the job. It returns the correct object type for the parsed email and leads a profitable life.

But.
I feel I've missed a trick. My OO design skills are poor crap. But hey, I'm a Unix Sys admin so for the Perl I write OO is usually a pointless overhead, especially one liners :-).

Seriously, I wonder if my parsing classes should be sub classes of a parent as they all have the same attributes (nearly) and only have the one method? So it would seem so but I'm not sure what benefit that would give me?

Also am I complicating things by returning objects of a different class? I think that my severity attribute is only there so I don't have to call ref $obj in the calling code.

As an aside I'm reading http://designpatternsinruby.com/ and since Ruby is Perl Lite I find it a readable and informative. Anyone know of a decent Perl design patterns reference?

package MailReader; BEGIN { push @INC, "U:\Perl"; } use Moose; use Harmless; use Critical; use UnSeen; has 'severity' => ( is => 'rw', isa => 'Str', default => 'unknown' ); has 'mailbody' => ( is => 'rw', isa => 'Str' ); sub parse_body { my $self = shift; # Look for Segmentation faults my $cm = Critical->new(data => $self->mailbody()); $cm->analysis(); if ($cm->is_critical) { $self->severity('critical'); return $cm; } # harmless my $hl = Harmless->new(data => $self->mailbody()); $hl->analysis(); if ($hl->is_harmless) { $self->severity('harmless'); return $hl; } # Still here then not seen this before my $us = UnSeen->new(data => $self->mailbody()); $us->analysis(); $self->severity('unknown'); return $us; } __PACKAGE__->meta->make_immutable; 1;

In reply to OO Design question. by Anonymous Monk

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.