| 1 | package Test::Deep::Matcher; | ||
| 2 | |||
| 3 | 12 | ▶ | use 5.008001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 12 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 12 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 12 | ▶ | use parent 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 12 | ▶ | use Test::Deep::Matcher::DataUtil; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 12 | our $VERSION = '0.01'; | |
| 10 | 12 | $VERSION = eval $VERSION; | |
| 11 | |||
| 12 | 12 | our @RefMatchers = qw( | |
| 13 | is_scalar_ref | ||
| 14 | is_array_ref | ||
| 15 | is_hash_ref | ||
| 16 | is_code_ref | ||
| 17 | is_glob_ref | ||
| 18 | ); | ||
| 19 | |||
| 20 | 12 | for my $name (@RefMatchers) { | |
| 21 | 12 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 35 | ▶ | *{$name} = sub { Test::Deep::Matcher::DataUtil->new($name, @_) }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 23 | } | ||
| 24 | |||
| 25 | 12 | our @PrimitiveMatchers = qw( | |
| 26 | is_value | ||
| 27 | is_string | ||
| 28 | is_number | ||
| 29 | is_integer | ||
| 30 | ); | ||
| 31 | |||
| 32 | 12 | for my $name (@PrimitiveMatchers) { | |
| 33 | 12 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | 32 | ▶ | *{$name} = sub { Test::Deep::Matcher::DataUtil->new($name, @_) }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 35 | } | ||
| 36 | |||
| 37 | 12 | our @EXPORT = ( | |
| 38 | @RefMatchers, | ||
| 39 | @PrimitiveMatchers, | ||
| 40 | ); | ||
| 41 | |||
| 42 | 12 | 1; | |
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | Test::Deep::Matcher - Type check matchers for Test::Deep | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use Test::More; | ||
| 51 | use Test::Deep; | ||
| 52 | use Test::Deep::Matcher; | ||
| 53 | |||
| 54 | my $got = +{ | ||
| 55 | foo => 'string', | ||
| 56 | bar => 100, | ||
| 57 | baz => [ 1, 2, 3 ], | ||
| 58 | quux => { foo => 'bar' }, | ||
| 59 | }; | ||
| 60 | |||
| 61 | cmp_deeply($got, +{ | ||
| 62 | foo => is_string, | ||
| 63 | bar => is_integer, | ||
| 64 | baz => is_array_ref, | ||
| 65 | quux => is_hash_ref, | ||
| 66 | }); | ||
| 67 | |||
| 68 | done_testing; | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | Test::Deep::Matcher is a collection of Test::Deep type check matchers. | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =head2 Reference Matchers | ||
| 77 | |||
| 78 | =over 4 | ||
| 79 | |||
| 80 | =item is_scalar_ref | ||
| 81 | |||
| 82 | Checks the value type is SCALAR reference. | ||
| 83 | |||
| 84 | =item is_array_ref | ||
| 85 | |||
| 86 | Checks the value type is ARRAY reference. | ||
| 87 | |||
| 88 | =item is_hash_ref | ||
| 89 | |||
| 90 | Checks the value type is HASH reference. | ||
| 91 | |||
| 92 | =item is_code_ref | ||
| 93 | |||
| 94 | Checks the value type is CODE reference. | ||
| 95 | |||
| 96 | =item is_glob_ref | ||
| 97 | |||
| 98 | Checks the value type is GLOB reference. | ||
| 99 | |||
| 100 | =back | ||
| 101 | |||
| 102 | =head2 Primitive Matchers | ||
| 103 | |||
| 104 | =over 4 | ||
| 105 | |||
| 106 | =item is_value | ||
| 107 | |||
| 108 | Checks the value is primitive, is B<not undef>. | ||
| 109 | |||
| 110 | =item is_string | ||
| 111 | |||
| 112 | Checks the value is string, has length. | ||
| 113 | |||
| 114 | =item is_number | ||
| 115 | |||
| 116 | Checks the value is number. | ||
| 117 | |||
| 118 | =item is_integer | ||
| 119 | |||
| 120 | Checks the value is integer, is also number. | ||
| 121 | |||
| 122 | =back | ||
| 123 | |||
| 124 | =head1 AUTHOR | ||
| 125 | |||
| 126 | NAKAGAWA Masaki E<lt>masaki@cpan.orgE<gt> | ||
| 127 | |||
| 128 | =head1 LICENSE | ||
| 129 | |||
| 130 | This library is free software; you can redistribute it and/or modify | ||
| 131 | it under the same terms as Perl itself. | ||
| 132 | |||
| 133 | =head1 SEE ALSO | ||
| 134 | |||
| 135 | L<Test::Deep>, <Data::Util> | ||
| 136 | |||
| 137 | =cut | ||