App-SimpleBackuper

 view release on metacpan or  search on metacpan

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN


sub true
{
  bool(1);
}

sub false
{
  bool(0);
}

sub builder
{
  if (@_)
  {
    $Test = shift;
  }
  return $Test;
}

1;

=pod

=encoding UTF-8

=head1 NAME

Test::Deep - Extremely flexible deep comparison

=head1 VERSION

version 1.204

=head1 SYNOPSIS

  use Test::More tests => $Num_Tests;
  use Test::Deep;

  cmp_deeply(
    $actual_horrible_nested_data_structure,
    $expected_horrible_nested_data_structure,
    "got the right horrible nested data structure"
  );

  cmp_deeply(
    $object,
    methods(name => "John", phone => "55378008"),
    "object methods ok"
  );

  cmp_deeply(
    \@array,
    [$hash1, $hash2, ignore()],
    "first 2 elements are as expected, ignoring 3"
  );

  cmp_deeply(
    $object,
    noclass({value => 5}),
    "object looks ok, not checking its class"
  );

  cmp_deeply(
    \@result,
    bag('a', 'b', {key => [1, 2]}),
    "array has the 3 things we wanted in some order"
  );

=head1 DESCRIPTION

If you don't know anything about automated testing in Perl then you should
probably read about L<Test::Simple> and L<Test::More> before preceding.
Test::Deep uses the L<Test::Builder> framework.

Test::Deep gives you very flexible ways to check that the result you got is
the result you were expecting. At its simplest it compares two structures
by going through each level, ensuring that the values match, that arrays and
hashes have the same elements and that references are blessed into the
correct class. It also handles circular data structures without getting
caught in an infinite loop.

Where it becomes more interesting is in allowing you to do something besides
simple exact comparisons. With strings, the C<eq> operator checks that 2
strings are exactly equal but sometimes that's not what you want. When you
don't know exactly what the string should be but you do know some things
about how it should look, C<eq> is no good and you must use pattern matching
instead. Test::Deep provides pattern matching for complex data structures

Test::Deep has B<I<a lot>> of exports.  See L</EXPORTS> below.

=head1 PERL VERSION

This library should run on perls released even a long time ago.  It should work
on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the
minimum required version will not be increased.  The version may be increased
for any reason, and there is no promise that patches will be accepted to lower
the minimum required perl.

=head1 EXAMPLES

How Test::Deep works is much easier to understand by seeing some examples.

=head2 Without Test::Deep

Say you want to test a function which returns a string. You know that your
string should be a 7 digit number beginning with 0, C<eq> is no good in this
situation, you need a regular expression. So you could use Test::More's
C<like()> function:

  like($string, qr/^0[0-9]{6}$/, "number looks good");

Similarly, to check that a string looks like a name, you could do:

  like($string, qr/^(Mr|Mrs|Miss) \w+ \w+$/,
    "got title, first and last name");

Now imagine your function produces a hash with some personal details in it.
You want to make sure that there are 2 keys, Name and Phone and that the
name looks like a name and the phone number looks like a phone number. You
could do:

  $hash = make_person();
  like($hash->{Name}, qr/^(Mr|Mrs|Miss) \w+ \w+$/, "name ok");
  like($hash->{Phone}, qr/^0[0-9]{6}$/, "phone ok");
  is(scalar keys %$hash, 2, "correct number of keys");

But that's not quite right, what if make_person has a serious problem and
didn't even return a hash? We really need to write

  if (ref($hash) eq "HASH")
  {
    like($hash->{Name}, qr/^(Mr|Mrs|Miss) \w+ \w+$/, "name ok");
    like($hash->{Phone}, qr/^0[0-9]{6}$/, "phone ok");
    is(scalar keys %$hash, 2, "correct number of keys");
  }
  else
  {
    fail("person not a hash");
    fail("person not a hash");
    fail("person not a hash"); # need 3 to keep the plan correct
  }

Already this is getting messy, now imagine another entry in the hash, an
array of children's names. This would require

  if (ref($hash) eq "HASH")
  {
    like($hash->{Name}, $name_pat, "name ok");
    like($hash->{Phone}, '/^0d{6}$/', "phone ok");
    my $cn = $hash->{ChildNames};
    if (ref($cn) eq "ARRAY")
    {
      foreach my $child (@$cn)
      {
        like($child, $name_pat);
      }
    }
    else
    {
        fail("child names not an array")
    }
  }
  else
  {
    fail("person not a hash");
  }

This is a horrible mess and because we don't know in advance how many
children's names there will be, we can't make a plan for our test anymore
(actually, we could but it would make things even more complicated).

Test::Deep to the rescue.

=head2 With Test::Deep

  my $name_re = re('^(Mr|Mrs|Miss) \w+ \w+$');
  cmp_deeply(
    $person,
    {

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN

    manager => methods(@manager_methods),
    coder => methods(@coder_methods)
  }

there is no way to know which if manager and coder will be tested first. If
the methods you are testing depend on and alter global variables or if
manager and coder are the same object then you may run into problems.

=head3 listmethods

  cmp_deeply( $got, listmethods(%hash) );

C<%hash> is a hash of pairs mapping method names to expected return values.

This is almost identical to methods() except the methods are called in list
context instead of scalar context. This means that the expected return
values supplied must be in array references.

  cmp_deeply(
    $obj,
    listmethods(
      name => [ "John" ],
      ["favourites", "food"] => ["Mapo tofu", "Gongbao chicken"]
    )
  );

is the equivalent of checking that

  cmp_deeply([$obj->name], ["John"]);
  cmp_deeply([$obj->favourites("food")], ["Mapo tofu", "Gongbao chicken"]);

The methods will be called in the order you supply them.

B<NOTE> The same caveats apply as for methods().

=head3 shallow

  cmp_deeply( $got, shallow($thing) );

C<$thing> is a ref.

This prevents Test::Deep from looking inside C<$thing>. It allows you to
check that C<$got_v> and C<$thing> are references to the same variable. So

  my @a = @b = (1, 2, 3);
  cmp_deeply(\@a, \@b);

will pass because C<@a> and C<@b> have the same elements however

  cmp_deeply(\@a, shallow(\@b))

will fail because although C<\@a> and C<\@b> both contain C<1, 2, 3> they are
references to different arrays.

=head3 noclass

  cmp_deeply( $got, noclass($thing) );

C<$thing> is a structure to be compared against.

This makes Test::Deep ignore the class of objects, so it just looks at the
data they contain. Class checking will be turned off until Test::Deep is
finished comparing C<$got_v> against C<$thing>. Once Test::Deep comes out of
C<$thing> it will go back to its previous setting for checking class.

This can be useful when you want to check that objects have been
constructed correctly but you don't want to write lots of
C<bless>es. If C<@people> is an array of Person objects then

  cmp_deeply(\@people, [
    bless {name => 'John', phone => '555-5555'}, "Person",
    bless {name => 'Anne', phone => '444-4444'}, "Person",
  ]);

can be replaced with

  cmp_deeply(\@people, noclass([
    {name => 'John', phone => '555-5555'},
    {name => 'Anne', phone => '444-4444'}
  ]));

However, this is testing so you should also check that the objects are
blessed correctly. You could use a map to bless all those hashes or you
could do a second test like

  cmp_deeply(\@people, array_each(isa("Person"));

=head3 useclass

  cmp_deeply( $got, useclass($thing) );

This turns back on the class comparison while inside a C<noclass()>.

  cmp_deeply(
    $got,
    noclass(
      [
        useclass( $object )
      ]
    )
  )

In this example the class of the array reference in C<$got> is ignored but
the class of C<$object> is checked, as is the class of everything inside
C<$object>.

=head3 re

  cmp_deeply( $got, re($regexp, $capture_data, $flags) );

C<$regexp> is either a regular expression reference produced with C<qr/.../>
or a string which will be used to construct a regular expression.

C<$capture_data> is optional and is used to check the strings captured by an
regex. This should can be an array ref or a Test::Deep comparator that works
on array refs.

C<$flags> is an optional string which controls whether the regex runs as a
global match. If C<$flags> is "g" then the regex will run as C<m/$regexp/g>.

Without C<$capture_data>, this simply compares C<$got_v> with the regular

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN

  foreach my $got_v (@$got) {
    cmp_deeply($got_v, $common_tests)
  }

Except it will not explode if C<$got> is not an array reference. It will
check that each of the objects in C<@$got> is a MyFile and that each one
gives the correct results for its methods.

You could go further, if for example there were 3 files and you knew the
size of each one you could do this

  cmp_deeply(
    $got,
    all(
      array_each($common_tests),
      [
        methods(size => 1000),
        methods(size => 200),
        methods(size => 20)
      ]
    )
  )
  cmp_deeply($got, array_each($structure));

=head3 hash_each

  cmp_deeply( \%got, hash_each($thing) );

This test behaves like C<array_each> (see above) but tests that each hash
value passes its tests.

=head3 str

  cmp_deeply( $got, str($string) );

$string is a string.

This will stringify C<$got_v> and compare it to C<$string> using C<eq>, even
if C<$got_v> is a ref. It is useful for checking the stringified value of an
overloaded reference.

=head3 num

  cmp_deeply( $got, num($number, $tolerance) );

C<$number> is a number.

C<$tolerance> is an optional number.

This will add 0 to C<$got_v> and check if it's numerically equal to
C<$number>, even if C<$got_v> is a ref. It is useful for checking the
numerical value of an overloaded reference. If C<$tolerance> is supplied
then this will check that C<$got_v> and C<$exp_v> are less than
C<$tolerance> apart. This is useful when comparing floating point numbers as
rounding errors can make it hard or impossible for C<$got_v> to be exactly
equal to C<$exp_v>. When C<$tolerance> is supplied, the test passes if
C<abs($got_v - $exp_v) <= $tolerance>.

B<Note> in Perl, C<"12blah" == 12> because Perl will be smart and convert
"12blah" into 12. You may not want this. There was a strict mode but that is
now gone. A "looks like a number" test will replace it soon. Until then you
can usually just use the string() comparison to be more strict. This will
work fine for almost all situations, however it will not work when <$got_v>
is an overloaded value who's string and numerical values differ.

=head3 bool, true, false

  cmp_deeply( $got, bool($value) );
  cmp_deeply( $got, true );
  cmp_deeply( $got, false );

C<$value> is anything you like but it's probably best to use 0 or 1

This will check that C<$got_v> and C<$value> have the same truth value, that
is they will give the same result when used in boolean context, like in an
C<if()> statement.

B<Note:> C<true> and C<false> are only imported by special request.

=head3 code

  cmp_deeply( $got, code(\&subref) );

C<\&subref> is a reference to a subroutine which will be passed a single
argument, it then should return a true or false and possibly a string

This will pass C<$got_v> to the subroutine which returns true or false to
indicate a pass or fail. Fails can be accompanied by a diagnostic string
which gives an explanation of why it's a fail.

  sub check_name
  {
    my $name = shift;
    if ($boss->likes($name))
    {
      return 1;
    }
    else
    {
      return (0, "the boss doesn't like your name");
    }
  }

  cmp_deeply("Brian", code(\&check_name));

=head2 SET COMPARISONS

Set comparisons give special semantics to array comparisons:

=over 4

=item * The order of items in a set is irrelevant

=item * The presence of duplicate items in a set is ignored.

=back

As such, in any set comparison, the following arrays are equal:

  [ 1, 2 ]
  [ 1, 1, 2 ]

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN


=item *

Mohammad S Anwar <mohammad.anwar@yahoo.com>

=item *

Peter Haworth <peter.haworth@headforwards.com>

=item *

Philip J. Ludlam <p.ludlam@cv-library.co.uk>

=item *

Ricardo Signes <rjbs@semiotic.systems>

=item *

Zoffix Znet <cpan@zoffix.com>

=back

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2003 by Fergal Daly.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__

#pod =head1 SYNOPSIS
#pod
#pod   use Test::More tests => $Num_Tests;
#pod   use Test::Deep;
#pod
#pod   cmp_deeply(
#pod     $actual_horrible_nested_data_structure,
#pod     $expected_horrible_nested_data_structure,
#pod     "got the right horrible nested data structure"
#pod   );
#pod
#pod   cmp_deeply(
#pod     $object,
#pod     methods(name => "John", phone => "55378008"),
#pod     "object methods ok"
#pod   );
#pod
#pod   cmp_deeply(
#pod     \@array,
#pod     [$hash1, $hash2, ignore()],
#pod     "first 2 elements are as expected, ignoring 3"
#pod   );
#pod
#pod   cmp_deeply(
#pod     $object,
#pod     noclass({value => 5}),
#pod     "object looks ok, not checking its class"
#pod   );
#pod
#pod   cmp_deeply(
#pod     \@result,
#pod     bag('a', 'b', {key => [1, 2]}),
#pod     "array has the 3 things we wanted in some order"
#pod   );
#pod
#pod =head1 DESCRIPTION
#pod
#pod If you don't know anything about automated testing in Perl then you should
#pod probably read about L<Test::Simple> and L<Test::More> before preceding.
#pod Test::Deep uses the L<Test::Builder> framework.
#pod
#pod Test::Deep gives you very flexible ways to check that the result you got is
#pod the result you were expecting. At its simplest it compares two structures
#pod by going through each level, ensuring that the values match, that arrays and
#pod hashes have the same elements and that references are blessed into the
#pod correct class. It also handles circular data structures without getting
#pod caught in an infinite loop.
#pod
#pod Where it becomes more interesting is in allowing you to do something besides
#pod simple exact comparisons. With strings, the C<eq> operator checks that 2
#pod strings are exactly equal but sometimes that's not what you want. When you
#pod don't know exactly what the string should be but you do know some things
#pod about how it should look, C<eq> is no good and you must use pattern matching
#pod instead. Test::Deep provides pattern matching for complex data structures
#pod
#pod Test::Deep has B<I<a lot>> of exports.  See L</EXPORTS> below.
#pod
#pod =head1 EXAMPLES
#pod
#pod How Test::Deep works is much easier to understand by seeing some examples.
#pod
#pod =head2 Without Test::Deep
#pod
#pod Say you want to test a function which returns a string. You know that your
#pod string should be a 7 digit number beginning with 0, C<eq> is no good in this
#pod situation, you need a regular expression. So you could use Test::More's
#pod C<like()> function:
#pod
#pod   like($string, qr/^0[0-9]{6}$/, "number looks good");
#pod
#pod Similarly, to check that a string looks like a name, you could do:
#pod
#pod   like($string, qr/^(Mr|Mrs|Miss) \w+ \w+$/,
#pod     "got title, first and last name");
#pod
#pod Now imagine your function produces a hash with some personal details in it.
#pod You want to make sure that there are 2 keys, Name and Phone and that the
#pod name looks like a name and the phone number looks like a phone number. You
#pod could do:
#pod
#pod   $hash = make_person();
#pod   like($hash->{Name}, qr/^(Mr|Mrs|Miss) \w+ \w+$/, "name ok");
#pod   like($hash->{Phone}, qr/^0[0-9]{6}$/, "phone ok");
#pod   is(scalar keys %$hash, 2, "correct number of keys");
#pod
#pod But that's not quite right, what if make_person has a serious problem and
#pod didn't even return a hash? We really need to write
#pod
#pod   if (ref($hash) eq "HASH")
#pod   {
#pod     like($hash->{Name}, qr/^(Mr|Mrs|Miss) \w+ \w+$/, "name ok");
#pod     like($hash->{Phone}, qr/^0[0-9]{6}$/, "phone ok");
#pod     is(scalar keys %$hash, 2, "correct number of keys");
#pod   }
#pod   else
#pod   {
#pod     fail("person not a hash");
#pod     fail("person not a hash");
#pod     fail("person not a hash"); # need 3 to keep the plan correct
#pod   }
#pod
#pod Already this is getting messy, now imagine another entry in the hash, an
#pod array of children's names. This would require
#pod
#pod
#pod   if (ref($hash) eq "HASH")
#pod   {
#pod     like($hash->{Name}, $name_pat, "name ok");
#pod     like($hash->{Phone}, '/^0d{6}$/', "phone ok");
#pod     my $cn = $hash->{ChildNames};
#pod     if (ref($cn) eq "ARRAY")
#pod     {
#pod       foreach my $child (@$cn)
#pod       {
#pod         like($child, $name_pat);
#pod       }
#pod     }
#pod     else
#pod     {
#pod         fail("child names not an array")
#pod     }
#pod   }
#pod   else
#pod   {
#pod     fail("person not a hash");
#pod   }
#pod
#pod This is a horrible mess and because we don't know in advance how many
#pod children's names there will be, we can't make a plan for our test anymore
#pod (actually, we could but it would make things even more complicated).
#pod
#pod Test::Deep to the rescue.
#pod
#pod =head2 With Test::Deep
#pod
#pod   my $name_re = re('^(Mr|Mrs|Miss) \w+ \w+$');
#pod   cmp_deeply(
#pod     $person,

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN

#pod     manager => methods(@manager_methods),
#pod     coder => methods(@coder_methods)
#pod   }
#pod
#pod there is no way to know which if manager and coder will be tested first. If
#pod the methods you are testing depend on and alter global variables or if
#pod manager and coder are the same object then you may run into problems.
#pod
#pod =head3 listmethods
#pod
#pod   cmp_deeply( $got, listmethods(%hash) );
#pod
#pod C<%hash> is a hash of pairs mapping method names to expected return values.
#pod
#pod This is almost identical to methods() except the methods are called in list
#pod context instead of scalar context. This means that the expected return
#pod values supplied must be in array references.
#pod
#pod   cmp_deeply(
#pod     $obj,
#pod     listmethods(
#pod       name => [ "John" ],
#pod       ["favourites", "food"] => ["Mapo tofu", "Gongbao chicken"]
#pod     )
#pod   );
#pod
#pod is the equivalent of checking that
#pod
#pod   cmp_deeply([$obj->name], ["John"]);
#pod   cmp_deeply([$obj->favourites("food")], ["Mapo tofu", "Gongbao chicken"]);
#pod
#pod The methods will be called in the order you supply them.
#pod
#pod B<NOTE> The same caveats apply as for methods().
#pod
#pod =head3 shallow
#pod
#pod   cmp_deeply( $got, shallow($thing) );
#pod
#pod C<$thing> is a ref.
#pod
#pod This prevents Test::Deep from looking inside C<$thing>. It allows you to
#pod check that C<$got_v> and C<$thing> are references to the same variable. So
#pod
#pod   my @a = @b = (1, 2, 3);
#pod   cmp_deeply(\@a, \@b);
#pod
#pod will pass because C<@a> and C<@b> have the same elements however
#pod
#pod   cmp_deeply(\@a, shallow(\@b))
#pod
#pod will fail because although C<\@a> and C<\@b> both contain C<1, 2, 3> they are
#pod references to different arrays.
#pod
#pod =head3 noclass
#pod
#pod   cmp_deeply( $got, noclass($thing) );
#pod
#pod C<$thing> is a structure to be compared against.
#pod
#pod This makes Test::Deep ignore the class of objects, so it just looks at the
#pod data they contain. Class checking will be turned off until Test::Deep is
#pod finished comparing C<$got_v> against C<$thing>. Once Test::Deep comes out of
#pod C<$thing> it will go back to its previous setting for checking class.
#pod
#pod This can be useful when you want to check that objects have been
#pod constructed correctly but you don't want to write lots of
#pod C<bless>es. If C<@people> is an array of Person objects then
#pod
#pod   cmp_deeply(\@people, [
#pod     bless {name => 'John', phone => '555-5555'}, "Person",
#pod     bless {name => 'Anne', phone => '444-4444'}, "Person",
#pod   ]);
#pod
#pod can be replaced with
#pod
#pod   cmp_deeply(\@people, noclass([
#pod     {name => 'John', phone => '555-5555'},
#pod     {name => 'Anne', phone => '444-4444'}
#pod   ]));
#pod
#pod However, this is testing so you should also check that the objects are
#pod blessed correctly. You could use a map to bless all those hashes or you
#pod could do a second test like
#pod
#pod   cmp_deeply(\@people, array_each(isa("Person"));
#pod
#pod =head3 useclass
#pod
#pod   cmp_deeply( $got, useclass($thing) );
#pod
#pod This turns back on the class comparison while inside a C<noclass()>.
#pod
#pod   cmp_deeply(
#pod     $got,
#pod     noclass(
#pod       [
#pod         useclass( $object )
#pod       ]
#pod     )
#pod   )
#pod
#pod In this example the class of the array reference in C<$got> is ignored but
#pod the class of C<$object> is checked, as is the class of everything inside
#pod C<$object>.
#pod
#pod =head3 re
#pod
#pod   cmp_deeply( $got, re($regexp, $capture_data, $flags) );
#pod
#pod C<$regexp> is either a regular expression reference produced with C<qr/.../>
#pod or a string which will be used to construct a regular expression.
#pod
#pod C<$capture_data> is optional and is used to check the strings captured by an
#pod regex. This should can be an array ref or a Test::Deep comparator that works
#pod on array refs.
#pod
#pod C<$flags> is an optional string which controls whether the regex runs as a
#pod global match. If C<$flags> is "g" then the regex will run as C<m/$regexp/g>.
#pod
#pod Without C<$capture_data>, this simply compares C<$got_v> with the regular

local/lib/perl5/Test/Deep.pm  view on Meta::CPAN

#pod   foreach my $got_v (@$got) {
#pod     cmp_deeply($got_v, $common_tests)
#pod   }
#pod
#pod Except it will not explode if C<$got> is not an array reference. It will
#pod check that each of the objects in C<@$got> is a MyFile and that each one
#pod gives the correct results for its methods.
#pod
#pod You could go further, if for example there were 3 files and you knew the
#pod size of each one you could do this
#pod
#pod   cmp_deeply(
#pod     $got,
#pod     all(
#pod       array_each($common_tests),
#pod       [
#pod         methods(size => 1000),
#pod         methods(size => 200),
#pod         methods(size => 20)
#pod       ]
#pod     )
#pod   )
#pod   cmp_deeply($got, array_each($structure));
#pod
#pod =head3 hash_each
#pod
#pod   cmp_deeply( \%got, hash_each($thing) );
#pod
#pod This test behaves like C<array_each> (see above) but tests that each hash
#pod value passes its tests.
#pod
#pod =head3 str
#pod
#pod   cmp_deeply( $got, str($string) );
#pod
#pod $string is a string.
#pod
#pod This will stringify C<$got_v> and compare it to C<$string> using C<eq>, even
#pod if C<$got_v> is a ref. It is useful for checking the stringified value of an
#pod overloaded reference.
#pod
#pod =head3 num
#pod
#pod   cmp_deeply( $got, num($number, $tolerance) );
#pod
#pod C<$number> is a number.
#pod
#pod C<$tolerance> is an optional number.
#pod
#pod This will add 0 to C<$got_v> and check if it's numerically equal to
#pod C<$number>, even if C<$got_v> is a ref. It is useful for checking the
#pod numerical value of an overloaded reference. If C<$tolerance> is supplied
#pod then this will check that C<$got_v> and C<$exp_v> are less than
#pod C<$tolerance> apart. This is useful when comparing floating point numbers as
#pod rounding errors can make it hard or impossible for C<$got_v> to be exactly
#pod equal to C<$exp_v>. When C<$tolerance> is supplied, the test passes if
#pod C<abs($got_v - $exp_v) <= $tolerance>.
#pod
#pod B<Note> in Perl, C<"12blah" == 12> because Perl will be smart and convert
#pod "12blah" into 12. You may not want this. There was a strict mode but that is
#pod now gone. A "looks like a number" test will replace it soon. Until then you
#pod can usually just use the string() comparison to be more strict. This will
#pod work fine for almost all situations, however it will not work when <$got_v>
#pod is an overloaded value who's string and numerical values differ.
#pod
#pod =head3 bool, true, false
#pod
#pod   cmp_deeply( $got, bool($value) );
#pod   cmp_deeply( $got, true );
#pod   cmp_deeply( $got, false );
#pod
#pod C<$value> is anything you like but it's probably best to use 0 or 1
#pod
#pod This will check that C<$got_v> and C<$value> have the same truth value, that
#pod is they will give the same result when used in boolean context, like in an
#pod C<if()> statement.
#pod
#pod B<Note:> C<true> and C<false> are only imported by special request.
#pod
#pod =head3 code
#pod
#pod   cmp_deeply( $got, code(\&subref) );
#pod
#pod C<\&subref> is a reference to a subroutine which will be passed a single
#pod argument, it then should return a true or false and possibly a string
#pod
#pod This will pass C<$got_v> to the subroutine which returns true or false to
#pod indicate a pass or fail. Fails can be accompanied by a diagnostic string
#pod which gives an explanation of why it's a fail.
#pod
#pod   sub check_name
#pod   {
#pod     my $name = shift;
#pod     if ($boss->likes($name))
#pod     {
#pod       return 1;
#pod     }
#pod     else
#pod     {
#pod       return (0, "the boss doesn't like your name");
#pod     }
#pod   }
#pod
#pod   cmp_deeply("Brian", code(\&check_name));
#pod
#pod =head2 SET COMPARISONS
#pod
#pod Set comparisons give special semantics to array comparisons:
#pod
#pod =over 4
#pod
#pod =item * The order of items in a set is irrelevant
#pod
#pod =item * The presence of duplicate items in a set is ignored.
#pod
#pod =back
#pod
#pod As such, in any set comparison, the following arrays are equal:
#pod
#pod   [ 1, 2 ]
#pod   [ 1, 1, 2 ]



( run in 2.509 seconds using v1.01-cache-2.11-cpan-d8267643d1d )