Invoked with perl -wc, both test and module say 'syntax OK'. This seems so simple. I'm apparently missing something pretty obvious here. Any ideas what that might be?

Here is what I've got:

1..2 ok 1 - use YMD::WWW::DB; not ok 2 - YMD::WWW::DB->can(...) # Failed test 'YMD::WWW::DB->can(...)' # at t/08-db.t line 14. # YMD::WWW::DB->can('We can access the ->connect() method') failed # Testing YMD::WWW::DB 0.01, Perl 5.008008, /var/usr/bin/perl # Looks like you failed 1 test of 2.
So says my simple test file. The module it is supposed to be exercising says this:

package YMD::WWW::DB; use warnings; use strict; use DBI; use Data::Dumper; sub connect { my $self = shift; my $db = shift; # print STDERR "->connect() says that \$db is: " . Dumper(\$db); my $db_driver = $db->{'db_driver'}; my $host_name = $db->{'db_host'}; my $db_name = $db->{'db_name'}; my $USER = $db->{'db_user'}; my $PASSWORD = $db->{'db_pw'}; my $dsn = "DBI:$db_driver:host=$host_name;database=$db_name"; if($db->{'db_ssl'}){ $dsn .= ';sslmode=require'; } # print $dsn,"\n"; return (DBI->connect($dsn,$USER,$PASSWORD, {PrintError => 0, RaiseError => 1})); } 1; # End of YMD::WWW::DB
and the test itself reads:

#!perl -T use Test::More tests => 2; use lib qw{/home/hesco/sandbox/YMD-WWW-SamplePhoneCall/lib}; BEGIN { use_ok( 'YMD::WWW::DB' ); } use YMD::WWW::DB; can_ok('YMD::WWW::DB','connect','We can access the ->connect() method' +); diag( "Testing YMD::WWW::DB $YMD::WWW::DB::VERSION, Perl $], $^X" );
I would think that my module->can('method'), even if I haven't yet built the config hash to pass it on its interface. Any clues what I might be missing here, please?

-- Hugh

UPDATE:

Thanks folks, that was exactly it. I found and corrected three other bugs in this code simply preparing this post, but it never occurred to me to perldoc Test::More for the can_ok function. I just assumed I knew how to use that one. Thanks again. I'll get back to work on this project after getting some groceries in the house.

if( $lal && $lol ) { $life++; }

In reply to Can't find my method . . . by hesco

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.