File Coverage

blib/lib/Config/Strict/UserConstraints.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 6 66.6
condition 3 9 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 32 40 80.0


line stmt bran cond sub pod time code
1             package Config::Strict::UserConstraints;
2 6     6   117 use strict;
  6         14  
  6         386  
3 6     6   40 use warnings;
  6         10  
  6         745  
4              
5             our $VERSION = '0.07';
6              
7 6     6   39 use Carp qw(confess);
  6         12  
  6         499  
8 6     6   36 use Declare::Constraints::Simple-Library;
  6         12  
  6         89  
9              
10             #__PACKAGE__->install_into( 'Config::Strict' );
11              
12             sub make_constraint {
13 4     4 1 11 my ( $class, $name, $sub, $message ) = @_;
14             # $name ||= '__ANON__'; TODO?
15 4 50       29 confess "No name" unless $name;
16 4 50 33     54 confess "Not a coderef" unless $sub and ref $sub and ref $sub eq 'CODE';
      33        
17 4   33     30 $message ||= "Value doesn't pass $name constraint";
18              
19             # print "Making constraint $name...\n";
20             # This just registers $name as a DCS constraint and returns true:
21             constraint(
22             $name => sub {
23             # _result( $sub->( @_ ), $message );
24 19 100   19   57 $sub->( @_ ) ? _true : _false( $message );
25             }
26 4         37 );
27             }
28              
29             1;