NotSoTiny/Creator.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 90.2% 37 / 41 CC 4 SCAR 7.9
CC
4
Cov
94%
create_role
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« NotSoTiny.pm ↑ Summary
1  
2 package Role::NotSoTiny::Creator;
3 1 $Role::NotSoTiny::Creator::VERSION = '0.1.0'; # TRIAL
4 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Role::NotSoTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub create_role {
Subroutine create_role: called CC=4 SCAR=13.9
Pod undocumented
13 1 my ( $class, $package, %args ) = @_;
14 1 ▶ my $methods = $args{methods} // {};
Condition50%1/2
$args{"methods"} // {}
l!l
10
MC/DC0%0/1
$args{"methods"} // {}
$args{"methods"}
Truth table50%1/2
A
A= $args{"methods"}
Aresult
11
00
15 1 Role::NotSoTiny->make_role($package);
16 1 for my $meth ( keys %$methods ) {
17 1 my $code = $methods->{$meth};
18 1 ▶ croak qq{Not a coderef: $meth ($code)} unless ref $code eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $code eq "CODE" 0 1 1
19 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 *{"${package}::${meth}"} = $code;
21 }
22 1 return $package;
23 }
24  
25 1 1;
26  
27 #pod =encoding utf8
28 #pod
29 #pod =head1 NAME
30 #pod
31 #pod Role::NotSoTiny::Creator - Experiment with Role::Tiny / Create roles programmatically
32 #pod
33 #pod =head1 SYNOPSIS
34 #pod
35 #pod use Role::NotSoTiny::Creator ();
36 #pod
37 #pod my $role = Role::NotSoTiny::Creator->create_role(
38 #pod 'Foo',
39 #pod methods => {
40 #pod foo => sub {...}
41 #pod },
42 #pod );
43 #pod
44 #pod # runtime equivalent of
45 #pod package Foo;
46 #pod use Role::Tiny;
47 #pod sub foo {...}
48 #pod
49 #pod =head1 DESCRIPTION
50 #pod
51 #pod This module is an experiment with L<Role::Tiny>.
52 #pod It illustrates how the change in L<Role::NotSoTiny> makes easier
53 #pod to build functionality such as a programmatic role creator.
54 #pod
55 #pod =head1 METHODS
56 #pod
57 #pod L<Role::NotSoTiny::Creator> implements the following methods.
58 #pod
59 #pod =head2 make_role
60 #pod
61 #pod Role::NotSoTiny::Creator->create_role('Some::Package', methods => \%methods);
62 #pod
63 #pod Prepares a given package as a role.
64 #pod This is done by promoting the package to a L<Role::Tiny>
65 #pod and adding the given methods to its stash.
66 #pod
67 #pod =cut
68  
69 __END__
« NotSoTiny.pm ↑ Summary