Here is a simple Message object We use in our office: It stringifies into a simple message, or as a number will give a code, and evaluates as true or false as dictated by the user. It also allows you to push on some extra data with push, for debuging or general extra information on a message.

example of use:
#Message->new(<Number>,<MSG>,<BOOL>);
Message->new(12345,'This is my Message or error message',0);

package Message; use strict; use overload '""' => 'str', '0+' => 'num', 'bool' => 'bool', fallback +=> 1; ###################################################################### +######### sub new { my $class = shift; my $num = shift; my $str = shift; my $bool = shift; my $data = {num => $num, str => $str, bool => $bool, data => [], }; if ( ! defined $data->{bool} ) { $data->{bool} = ( $data->{num} ? 1 : 0 ); } bless $data, $class; if ( @_ ) { if ( ref $_[0] eq 'ARRAY' ) { foreach my $element (@_) { $data->push($element); } } else { $data->push(@_); } } return $data; } ###################################################################### +######### sub push { my $self = shift; my $obj = shift; push @{$self->{data}},$obj; } ###################################################################### +######### sub num { my $self = shift; return $self->{num}; } ###################################################################### +######### sub str { my $self = shift; return $self->{str}; } ###################################################################### +######### sub bool { my $self = shift; return $self->{bool}; } ###################################################################### +######### 1;

In reply to Re: Using overload. Any complete (simple) examples? by naholos
in thread Using overload. Any complete (simple) examples? by BrowserUk

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.