I can reproduce a similar behaviour if I remove
use DateTime;
from the package where foo is declared. Do you use DateTime in the package?
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; { package MyClass; use DateTime; sub foo { my ($self,$input) = @_; my @ymd = split("-",$input); my $date = { day => $ymd[2], month => $ymd[1], year => $ymd[0], }; my $dt = eval{DateTime->new($date)}; return unless $dt; $date->{dt} = $dt; return $date } sub new { bless {}, shift } } my $dt = 'MyClass'->new; my $result = $dt->foo('2001-01-01'); print Dumper $result;

Output:

$VAR1 = { 'dt' => bless( { 'utc_rd_days' => 730486, 'rd_nanosecs' => 0, 'local_rd_days' => 730486, 'utc_rd_secs' => 0, 'locale' => bless( { 'native_complete_name' + => 'English United States', 'en_territory' => 'Uni +ted States', 'en_language' => 'Engl +ish', 'en_complete_name' => +'English United States', 'native_territory' => +'United States', 'default_time_format_l +ength' => 'medium', 'default_date_format_l +ength' => 'medium', 'id' => 'en_US', 'native_language' => ' +English' }, 'DateTime::Locale::en +_US' ), 'utc_year' => 2002, 'formatter' => undef, 'offset_modifier' => 0, 'local_c' => { 'day_of_quarter' => 1, 'day' => 1, 'day_of_year' => 1, 'hour' => 0, 'second' => 0, 'quarter' => 1, 'minute' => 0, 'year' => 2001, 'month' => 1, 'day_of_week' => 1 }, 'local_rd_secs' => 0, 'tz' => bless( { 'offset' => 0, 'name' => 'floating' }, 'DateTime::TimeZone::Floa +ting' ) }, 'DateTime' ), 'month' => '01', 'day' => '01', 'year' => '2001' };
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re: hashref return fails by choroba
in thread hashref return fails 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.