1: When I only add strictures, as in the following code:
{ package MyDate; use strict; use warnings; sub AUTOLOAD { our $AUTOLOAD; say "Going into AUTOLOAD"; # Why doesn't this print? my $method = $AUTOLOAD; $method =~ s/.*:://; grep {$method eq $_} qw/yak day month/ or Carp::croak "Invalid + method: $method."; if ($method eq "day") { eval { sub day {(localtime)[3];} }; } elsif ($method eq "month") { eval { sub month {(localtime)[4] + 1;} }; } Carp::croak $@ if $@; goto &$method; } } ###################################################################### +################## package main; use strict; use warnings; say MyDate->day; say MyDate->month;
I get the following:
String found where operator expected at 879141.pl line 6, near "say "G +oing into AUTOLOAD"" (Do you need to predeclare say?) String found where operator expected at 879141.pl line 9, near "Carp:: +croak "Invalid method: $method."" (Do you need to predeclare Carp::croak?) syntax error at 879141.pl line 6, near "say "Going into AUTOLOAD"" syntax error at 879141.pl line 9, near "Carp::croak "Invalid method: $ +method."" BEGIN not safe after errors--compilation aborted at 879141.pl line 26.

The first error tells me that say needs to be imported, the second that Carp isn't loaded. If nothing was printed for you, then that package didn't have warnings enabled.

2: Your code looked like this: if (foo) { eval { sub bar {} } }. You were defining a sub inside the AUTOLOAD sub, and then executing that code by name, instead of assigning to another variable a coderef, like $code = sub { ... }; and then later calling it or using goto on it.

3: Notice that the "was called" statement is executed unconditionally, after it's determined that DESTROY wasn't called.

Actually I get the impression that AUTOLOAD isn't even being called.
It looks like you're trying to juggle the differences between the code I provided and the code your provided, and then trying to map them to the actual code you're running. This isn't working.

In reply to Re^3: say statements within 'sub AUTOLOAD' by Anonymous Monk
in thread say statements within 'sub AUTOLOAD' by ianyappy

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.