I think the problem is that you are taking a reference to the %default_values hash, instead of making a copy of it.

The point made by both davidrw and tlm is well taken. I tried it out by rewriting the relevant part of the constructor as follows:

warn "DV: " . \%default_values; my $self = ref($class) ? bless( +{ %default_values }, ref($class) +) : bless( +{ %default_values }, $class ); warn "self: " . $self;

It worked ...

... at first.

Then it didn't.

To keep my original posting to a reasonable length, I only included two test blocks in t/001_load.t. With the suggested revisions to the constructor, both passed.

However, the real-world module of which Woeisme is a distillation included additional test block both before and after the two listed originally. I first added those tests which, in the real-world test suite, occurred before the two cited.

failsafe( [ 'SUBJECT' => 'The quick brown fox jumps over the lazy dog', ], "^NAME is required", "Constructor correctly failed due to lack of NAME for module"); failsafe( [ 'NAME' => 'My::B!ad::Module', ], "^Module NAME contains illegal characters", "Constructor correctly failed due to illegal characters in module +name"); failsafe( [ 'NAME' => "My'BadModule", ], "^Module NAME contains illegal characters", "Perl 4-style single-quote path separators no longer supported");

And now the two original tests.

failsafe( [ 'NAME' => 'ABC::XYZ', 'SUBJECT' => '123456789012345678901234567890123456789012345', ], "^SUBJECTs are limited to 44 characters", "Constructor correctly failed due to SUBJECT > 44 characters"); failsafe( [ 'NAME' => 'GHI::DEF', 'AUTHOR' => { NAME => 'James E Keenan', CPANID => 'ABCDEFGHIJ', }, ], "^CPAN IDs are 3-9 characters", "Constructor correctly failed due to CPANID > 9 characters");

All tests passed. I added one more test similar to the last one.

failsafe( [ 'NAME' => 'ABC::XYZ', 'AUTHOR' => { NAME => 'James E Keenan', CPANID => 'AB', }, ], "^CPAN IDs are 3-9 characters", "Constructor correctly failed due to CPANID < 3 characters");

All tests still passed. But when I started to add more tests testing values for the other keys of the AUTHOR hash, I started to get exactly the same type of error as I reported yesterday. Adding one test:

failsafe( [ 'NAME' => 'ABC::Alpha', 'AUTHOR' => { NAME => 'James E Keenan', EMAIL => 'jkeenancpan.org', }, ], "^EMAIL addresses need to have an at sign", "Constructor correctly failed; e-mail must have '\@' sign");

... led to this error:

not ok 22 - Constructor correctly failed; e-mail must have '@' sign # Failed test (t\001_load.t at line 88) # 'CPAN IDs are 3-9 characters # EMAIL addresses need to have an at sign # # No such file or directory at t\001_load.t line 87 # ' # doesn't match '(?-xism:^EMAIL addresses need to have an at sign) +'

Note that in the last test block, I was not testing the CPANID key; only the NAME key (which should have PASSed) and the EMAIL key (which should have been the sole FAIL). There shouldn't have been any reference at all to the CPANID key.

So it appears we have not yet found the bug! Thanks for those who took the time to look at this. Any other ideas?


In reply to Re^2: Wrong Error Message When Testing for Failure of Constructor by jkeenan1
in thread Wrong Error Message When Testing for Failure of Constructor by jkeenan1

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.