NotSoTiny.pm

filter: Statementstmt 100% 35 / 35 Branchbran 50.0% 3 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 87.0% 47 / 54 CC 6 SCAR 13.0
CC
6
Cov
91%
make_role
6.3
BEGIN
1.0
BEGIN
1.0
CRAP 3.7
↑ Summary NotSoTiny/Creator.pm »
1  
2 package Role::NotSoTiny;
3 18 $Role::NotSoTiny::VERSION = '0.1.0'; # TRIAL
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 require Role::Tiny;
9 18 Role::Tiny->VERSION('2.000005');
10 18 our @ISA = qw(Role::Tiny);
11 }
12  
13 # Aliasing of Role::Tiny symbols
14 18 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 *INFO = \%Role::Tiny::INFO;
16 18 *APPLIED_TO = \%Role::Tiny::APPLIED_TO;
17 18 *ON_ROLE_CREATE = \@Role::Tiny::ON_ROLE_CREATE;
18  
19 18 *_getstash = \&Role::Tiny::_getstash;
20 18 ▶ *_getglob = \&Role::Tiny::_getglob;
Subroutine BEGIN: not called CC=1 SCAR=0.0
21 }
22  
23 18 our %INFO;
24 18 our %APPLIED_TO;
25 18 our @ON_ROLE_CREATE;
26  
27 58 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
28 58 my $target = caller;
29 58 my $me = shift;
30 58 strict->import;
31 58 warnings->import;
32 58 $me->_install_subs($target);
33 58 $me->make_role($target);
34 }
35  
36 60 ▶sub make_role {
Subroutine make_role: called CC=6 SCAR=18.5
Pod documented
37 60 my ( $me, $target ) = @_;
38 60 ▶ return if $me->is_role($target); # already exported into this package
Branch: 1 branch
BranchTrueFalseTotal
if $me->is_role($target) 0 60 60
39 60 $INFO{$target}{is_role} = 1;
40 # get symbol table reference
41 60 my $stash = _getstash($target);
42 # grab all *non-constant* (stash slot is not a scalarref) subs present
43 # in the symbol table and store their refaddrs (no need to forcibly
44 # inflate constant subs into real subs) with a map to the coderefs in
45 # case of copying or re-use
46 my @not_methods
47 60 ▶ = map +( ref $_ eq 'CODE' ? $_ : ref $_ ? () : *$_{CODE} || () ),
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 350 350
ref $_ ? : 0 350 350
Condition66%2/3
*$_{"CODE"} or ()
l!l&&r!l&&!r
291590
MC/DC0%0/2
*$_{"CODE"} or ()
*$_{"CODE"} ()
Truth table66%2/3
A or B
A= *$_{"CODE"}B= ()
ABresult
1X1
011
000
48 values %$stash;
49 60 @{ $INFO{$target}{not_methods} = {} }{@not_methods} = @not_methods;
50 # a role does itself
51 60 $APPLIED_TO{$target} = { $target => undef };
52 60 foreach my $hook (@ON_ROLE_CREATE) {
53 2 $hook->($target);
54 }
55 }
56  
57 18 1;
58  
59 #pod =encoding utf8
60 #pod
61 #pod =head1 NAME
62 #pod
63 #pod Role::NotSoTiny - Experiment with Role::Tiny / Role::NotSoTiny->make_role()
64 #pod
65 #pod =head1 SYNOPSIS
66 #pod
67 #pod use Role::NotSoTiny ();
68 #pod
69 #pod Role::NotSoTiny->make_role('Foo');
70 #pod *Foo::foo = sub {...};
71 #pod
72 #pod # runtime equivalent of
73 #pod package Foo;
74 #pod use Role::Tiny;
75 #pod sub foo {...}
76 #pod
77 #pod =head1 DESCRIPTION
78 #pod
79 #pod This module is an experiment with L<Role::Tiny>.
80 #pod The change here is being a proposed as a patch to the original code.
81 #pod See L<https://github.com/moose/Role-Tiny/pull/4>.
82 #pod
83 #pod =head1 METHODS
84 #pod
85 #pod L<Role::NotSoTiny> inherits all methods of L<Role::Tiny> and
86 #pod implements the following new ones.
87 #pod
88 #pod =head2 make_role
89 #pod
90 #pod Role::NotSoTiny->make_role('Some::Package');
91 #pod
92 #pod Promotes a given package to a role.
93 #pod No subroutines are imported into C<'Some::Package'>.
94 #pod
95 #pod =cut
96  
97 __END__
↑ Summary NotSoTiny/Creator.pm »