GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TEST::STREAM::COMPARE::CUSTOM (3)

.ds Aq ’

NAME

Test::Stream::Compare::Custom - Custom field check for comparisons.

CONTENTS

DEPRECATED

<B>This distribution is deprecatedB> in favor of Test2, Test2::Suite, and Test2::Workflow.

See Test::Stream::Manual::ToTest2 for a conversion guide.

DESCRIPTION

Sometimes you want to do something complicated or unusual when validating a field nested inside a deep data structure. You could pull it out of the structure and test it separately, or you can use this to embed the check. This provides a way for you to write custom checks for fields in deep comparisons.

SYNOPSIS



    my $cus = Test::Stream::Compare::Custom->new(
        name => IsRef,
        operator => ref(...),
        code => sub {
            my ($got, $exists, $operator, $name) = @_;
            return ref($got) ? 1 : 0;
        },
    );

    # Pass
    is(
        { a => 1, ref => {},   b => 2 },
        { a => 1, ref => $cus, b => 2 },
        "This will pass"
    );

    # Fail
    is(
        {a => 1, ref => notref, b => 2},
        {a => 1, ref => $cus,     b => 2},
        "This will fail"
    );



ARGUMENTS

Your custom sub will get 4 arguments:



    code => sub {
        my ($got, $exists, $operator, $name) = @_;
        return ref($got) ? 1 : 0;
    },



$_ is also localized to $got to make it easier for those who need to use regexes.
$got
$_ This is the value to be checked.
$exists This will be a boolean. This will be true if $got exists at all. If $exists is false then it means $got is not simply undef, but doesn’t exist at all (think checking the value of a hash key that does not exist).
$operator This is the operator specified at construction.
$name This is the name provided at construction.

METHODS

$code = $cus->code Get the coderef provided at construction.
$name = $cus->name Get the name provided at construction.
$op = $cus->operator Get the operator provided at construction
$bool = $cus->verify(got => $got, exists => $bool)

SOURCE

The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

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

See http://dev.perl.org/licenses/

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TEST::STREAM::COMPARE::CUSTOM (3) 2016-02-05

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.