File Coverage

blib/lib/Test/InDomain.pm
Criterion Covered Total %
statement 34 34 100.0
branch 3 6 50.0
condition 3 4 75.0
subroutine 9 9 100.0
pod 2 2 100.0
total 51 55 92.7


line stmt bran cond sub pod time code
1             package Test::InDomain;
2            
3 3     3   114177 use 5.010;
  3         11  
  3         111  
4 3     3   16 use strict;
  3         5  
  3         108  
5 3     3   15 use warnings;
  3         22  
  3         90  
6 3     3   5865 use parent 'Test::Builder::Module';
  3         1011  
  3         16  
7            
8 3     3   4111 use Data::Domain (); # empty list because import() is called explicitly below
  3         2054643  
  3         98  
9 3     3   32 use Scalar::Does;
  3         5  
  3         14  
10            
11             our $VERSION = '0.01';
12            
13             our @EXPORT = qw/in_domain not_in_domain/;
14            
15             sub import {
16 3     3   29 my ($class, @data_domain_import_args) = @_;
17            
18             # export functions in @EXPORT through Exporter
19 3         312 $class->export_to_level(1, $class);
20            
21             # export Data::Domain functions; by default: :all, one level up
22 3 50       19 unshift @data_domain_import_args, {}
23             unless does($data_domain_import_args[0], 'HASH');
24 3   50     2241 $data_domain_import_args[0]{into_level} //= 1;
25 3   100     19 $data_domain_import_args[1] //= ':all';
26 3         20 Data::Domain->import(@data_domain_import_args);
27             }
28            
29            
30             sub in_domain ($$;$) {
31 8     8 1 6406 my ($data, $domain, $name) = @_;
32            
33 8         55 my $err_msg = $domain->inspect($data);
34 8         4016 my $test_builder = __PACKAGE__->builder;
35 8         103 $test_builder->ok(!$err_msg, $name);
36 8 50       3152 $test_builder->diag($test_builder->explain($err_msg)) if $err_msg;
37             }
38            
39             sub not_in_domain ($$;$$) {
40 1     1 1 5 my ($data, $domain, $name, $want_explanation) = @_;
41            
42 1         5 my $err_msg = $domain->inspect($data);
43 1         82 my $test_builder = __PACKAGE__->builder;
44 1         9 $test_builder->ok($err_msg, $name);
45 1 50       188 $test_builder->note($test_builder->explain($err_msg)) if $want_explanation;
46             }
47            
48             1; # End of Test::InDomain
49            
50            
51             __END__