Anonymous subs to the rescue:
#!/usr/bin/perl use warnings; use strict; { package MyPackage; sub method1 { '<?xml version="1.0"?>' } sub method2 { '[?xml version="2.0"?][a][/a]' } } use Test::More; sub my_subtest { like( shift, qr/xml version=/, "XML Document"); # more tests on XML document text here.... } for my $method (qw/method1 method2/) { subtest "Checking $method" => sub { my_subtest(MyPackage->$method) + }; }
Update: Unfortunately, I am not able to use a sub returning a sub as in
sub new_test { my ($test, $method) = @_; return sub { $test->(MyPackage->$method) }; } for my $method (qw/method1 method2/) { subtest "Checking $method", new_test(\&my_subtest, $method); }

I am getting

Type of arg 2 to Test::More::subtest must be sub {} (not subroutine en +try)
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re^3: Test::More subtest parameters by choroba
in thread Test::More subtest parameters by space_monk

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.