While working with the DateTime module, I'm getting a very odd and frustrating error back from the Params::Validate module:
The 'locale' parameter (undef) to DateTime::new was an 'undef', which +is not one of the allowed types: scalar object at /usr/lib/perl5/site_perl/5.8.5/Params/ValidatePP.pm line 634 Params::Validate::__ANON__('The \'locale\' parameter (undef) to Da +teTime::new was an \'un...') called at /usr/lib/perl5/site_perl/5.8.5 +/Params/ValidatePP.pm line 485 Params::Validate::_validate_one_param('undef', 'HASH(0x1039fb0)', +'HASH(0xe04910)', 'The \'locale\' parameter (undef)') called at /usr/ +lib/perl5/site_perl/5.8.5/Params/ValidatePP.pm line 345 Params::Validate::validate('ARRAY(0xa87370)', 'HASH(0xe284a0)') ca +lled at /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi/Da +teTime.pm line 171 DateTime::new('undef', 'year', 2015, 'month', 08, 'day', 24, 'hour +', 17, ...) called at MonitorClass.pm line 80 MonitorClass::MakeDateTime('MonitorClass=HASH(0xf03430)', 2015, 08 +, 24, 17, 36, 47, 144) called at MonitorClass.pm line 196

This is driving me nuts, as the parameters sent to DateTime->new() are correct, as can be seen in the final line of my error. I'm not even able to reproduce the issue consistently. For the vast majority of cases my code works great but every morning when I get into work I see that it's thrown the above a few times.

I'm going to try explicitly setting the locale parameter each time I call DateTime->new(); but I'd rather understand what I'm doing wrong here.

Here's my method that's invoking DateTime->new(); it's ridiculously simple:
sub MakeDateTime { my $self = shift; my ($Year, $Month, $Day, $Hour, $Minute, $Second, $MilliSecond) = @_ +; my $DateTime = DateTime->new( year => $Year, month => $Month, day => $Day, hour => $Hour, minute => $Minute, second => $Second, nanosecond => ($MilliSecond * 1000000), time_zone => 'America/New_York', locale => 'en_US', ); return $DateTime; }

In reply to Strange Params::Validate Error by Stringer

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.