Being relatively new to OO perl, I need help understanding how to validate data upon creation in a perl object. My object consists of a variety of attributes which have to be matched up to a standard list of values. For example: Company A provides a data file containing a list of colors Red, Maroon, and Brick. For my XML, I only support Red and wish to convert all instances of Maroon and Brick to Red. I assume the proper place to do this is upon the creaton of the object and can use a configuration file to define Maroon and Brick as the color Red, such that if I pass:
my $test -> Car->new { provider => "Provider A", color => "Maroon" };
then the module will use the Provider A configuration file and create the instance as {provider=>"ProviderA",color=>"Red"};

Am I going about this the right way, and if so, how do I define in my new method to run a validate_color upon creation of the object?

Thanks for the help....

Edit by tye


In reply to Validation of Data in Module by rgatliff

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.