What you're trying to do is use 'symbolic' (or 'soft') references, which is officially Frowned Upon (and for good reason), not to mention precluded by the  use strict 'refs'; stricture (one of the strictures that  use strict; turns on). See discussion at Symbolic references in perlref, search PM for more comments. This stricture is turned off by the  no strict 'refs'; pragma. See strict.

What you may want to do is something like this (I'm using your original module):

use warnings; use strict; use Test::More 'no_plan'; BEGIN { use_ok('Mysimple_mod', qw (external) ) }; my $mod = 'Mysimple_mod'; ok ( defined( &external ), "#2 external is defined"); ok ( defined( &Mysimple_mod::internal ), "#3 internal is defined"); ok ( defined( &Mysimple_mod::bogus ), "#4 bogus subroutine"); ok ( defined( &{"${mod}::bogus"} ), "#5 bogus subroutine"); my @softies = qw(internal); # my @softies = qw(internal bogus); for my $softy (@softies) { my $func = "${mod}::$softy"; no strict 'refs'; ok( $func->(3) == 9, qq{invoke soft ref'd func $func( 9)} ); ok( $func->(3) == 10, qq{invoke soft ref'd func $func(10)} ); }
Output:
C:\@Work\Perl\monks\gctaylor1>perl test_soft_refs_1.pl ok 1 - use Mysimple_mod; ok 2 - \#2 external is defined ok 3 - \#3 internal is defined not ok 4 - \#4 bogus subroutine # Failed test (test_soft_refs_1.pl at line 77) not ok 5 - \#5 bogus subroutine # Failed test (test_soft_refs_1.pl at line 78) ok 6 - invoke soft ref'd func Mysimple_mod::internal( 9) not ok 7 - invoke soft ref'd func Mysimple_mod::internal(10) # Failed test (test_soft_refs_1.pl at line 87) 1..7 # Looks like you failed 3 tests of 7.
See what happens if you add  bogus to the  @softies array.

In reply to Re: Concatenate strings before Test::More::ok by AnomalousMonk
in thread Concatenate strings before Test::More::ok by gctaylor1

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.