File Coverage

blib/lib/HashDataRole/Spec/Basic.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 2 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 32 40.6


line stmt bran cond sub pod time code
1             package HashDataRole::Spec::Basic;
2              
3 3     3   441276 use strict;
  3         10  
  3         112  
4 3     3   562 use Role::Tiny;
  3         7248  
  3         18  
5 3     3   1295 use Role::Tiny::With;
  3         350  
  3         1165  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-01-22'; # DATE
9             our $DIST = 'HashData'; # DIST
10             our $VERSION = '0.1.2'; # VERSION
11              
12             # constructor
13             requires 'new';
14              
15             # mixin
16             with 'Role::TinyCommons::Iterator::Resettable';
17             with 'Role::TinyCommons::Collection::GetItemByKey';
18              
19             # provides
20              
21             my @role_prefixes = qw(HashDataRole Role::TinyCommons::Collection);
22             sub apply_roles {
23 0     0 1   my ($obj, @unqualified_roles) = @_;
24              
25 0           my @roles_to_apply;
26             ROLE:
27 0           for my $ur (@unqualified_roles) {
28             PREFIX:
29 0           for my $prefix (@role_prefixes) {
30 0           my ($mod, $modpm);
31 0           $mod = "$prefix\::$ur";
32 0           ($modpm = "$mod.pm") =~ s!::!/!g;
33 0           eval { require $modpm; 1 };
  0            
  0            
34 0 0         unless ($@) {
35             #print "D:$mod\n";
36 0           push @roles_to_apply, $mod;
37 0           next ROLE;
38             }
39             }
40 0           die "Can't find role '$ur' to apply (searched these prefixes: ".
41             join(", ", @role_prefixes);
42             }
43              
44 0           Role::Tiny->apply_roles_to_object($obj, @roles_to_apply);
45              
46             # return something useful
47 0           $obj;
48             }
49              
50             ###
51              
52             1;
53             # ABSTRACT: Required methods for all HashData::* classes
54              
55             __END__