File Coverage

blib/lib/WordListBase.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 6 33.3
condition 2 6 33.3
subroutine 2 2 100.0
pod 1 1 100.0
total 20 28 71.4


line stmt bran cond sub pod time code
1             package WordListBase;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2021-06-23'; # DATE
5             our $DIST = 'WordList'; # DIST
6             our $VERSION = '0.7.10'; # VERSION
7              
8 2     2   12 use strict 'subs', 'vars';
  2         3  
  2         381  
9              
10             sub new {
11 5     5 1 11 my $class = shift;
12              
13             # check for known and required parameters
14 5         13 my %params = @_;
15 5         9 my $param_spec = \%{"$class\::PARAMS"};
  5         27  
16 5         15 for my $param_name (keys %params) {
17 1 50       5 die "Unknown parameter '$param_name'" unless $param_spec->{$param_name};
18             }
19 5         14 for my $param_name (keys %$param_spec) {
20             die "Missing required parameter '$param_name'"
21 1 50 33     7 if $param_spec->{$param_name}{req} && !exists($params{$param_name});
22             # apply default
23             $params{$param_name} = $param_spec->{$param_name}{default}
24             if !defined($params{$param_name}) &&
25 1 0 33     4 exists $param_spec->{$param_name}{default};
26             }
27              
28             bless {
29 5         22 params => \%params,
30              
31             # we store this because applying roles to object will rebless the object
32             # into some other package.
33             orig_class => $class,
34             }, $class;
35             }
36              
37             1;
38             # ABSTRACT: WordList base class
39              
40             __END__