Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've got some weirdness I don't understand when I load a module with Test::More's use_ok()

I was using an array-reference prototype to pass an array by reference without the module user having to fuss about it -- but when I load the module with Test::More's use_ok() all the prototypes seem to be getting ignored.

What is it I'm missing ?

Here's a cut-down example module, CST2.pm:

package CST2; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(ArrayCount); sub ArrayCount(\@) { (my $array_Ref, undef) = @_; my $ct; foreach my $element (@{$array_Ref}) { $ct++ } $ct; } 1;
and a calling script,
#!/usr/bin/perl use strict; use warnings; use Test::More; #BEGIN:{ use_ok('CST2'); } use CST2; my @patternList = qw(one two three); my $count = ArrayCount(@patternList); print "$count\n";

With use CST2 everything works fine.

But if I change to BEGIN:{ use_ok('CST2'); }, then I get an error: 'Can't use string ("one") as an ARRAY ref while "strict refs" in use at CST2.pm line 12.'

To make the error go away, I have to change the call in the script to explicitly pass a reference my $count = ArrayCount(\@patternList);

Why is this happening? What is it I've missed, and should have done differently?

For what it's worth, perl --version tells me I'm running perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-thread-multi-64int (with 7 registered patches, see perl -V for more detail); and it's version 0.98 of Test::More

Thanks in advance,

JH.


In reply to Prototypes being ignored with use_ok() from Test:More ? by JPMH

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2015-07-04 21:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls