blib/lib/Venus/Role/Patchable.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 86.6% 26 / 30 CC 2 SCAR 2.5
CC
2
Cov
95%
patch
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Venus/Role/Doable.pm ↑ Summary blib/lib/Venus/Role/Tryable.pm »
1 package Venus::Role::Patchable;
2  
3 119 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 119 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 119 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 119 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # METHODS
13  
14 2 ▶sub patch {
Subroutine patch: called CC=2 SCAR=7.0
Pod documented
15 2 my ($self, $name, $code) = @_;
16  
17 2 require Venus::Space;
18  
19 2 ▶ my $space = Venus::Space->new(ref $self || $self);
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
20  
21 2 return $space->patch($name, $code);
22 }
23  
24 # EXPORTS
25  
26 121 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
27 121 ['patch']
28 }
29  
30 119 1;
31  
32  
33  
34 =head1 NAME
35  
36 Venus::Role::Patchable - Patchable Role
37  
38 =cut
39  
40 =head1 ABSTRACT
41  
42 Patchable Role for Perl 5
43  
44 =cut
45  
46 =head1 SYNOPSIS
47  
48 package Example;
49  
50 use Venus::Class;
51  
52 with 'Venus::Role::Patchable';
53  
54 package main;
55  
56 my $example = Example->new;
57  
58 # my $patch = $example->patch;
59  
60 # bless(.., "Venus::Space")
61  
62 =cut
63  
64 =head1 DESCRIPTION
65  
66 This package modifies the consuming package and provides methods for patching
67 (or monkey-patching) routines in the calling package using
68 L<Venus::Space/patch>.
69  
70 =cut
71  
72 =head1 METHODS
73  
74 This package provides the following methods:
75  
76 =cut
77  
78 =head2 patch
79  
80 patch(string $name, coderef $code) (Venus::Space)
81  
82 The patch method overwrites the named subroutine in the calling package using
83 L<Venus::Space/patch> returning a L<Venus::Space> object that can be used to
84 restore the original subroutine when L<Venus::Space/unpatch> is called.
85  
86 I<Since C<3.55>>
87  
88 =over 4
89  
90 =item patch example 1
91  
92 package Example;
93  
94 use Venus::Class;
95  
96 with 'Venus::Role::Patchable';
97  
98 sub test {
99 my ($self, @args) = @_;
100  
101 return [$self, @args];
102 }
103  
104 package main;
105  
106 my $example = Example->new;
107  
108 my $patch = $example->patch('test', sub {
109 my ($next, @args) = @_;
110  
111 return ['patched', @{$next->(@args)}];
112 });
113  
114 # bless(.., "Venus::Space")
115  
116 =back
117  
118 =cut
119  
120 =head1 AUTHORS
121  
122 Awncorp, C<awncorp@cpan.org>
123  
124 =cut
125  
126 =head1 LICENSE
127  
128 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
129  
130 This program is free software, you can redistribute it and/or modify it under
131 the terms of the Apache license version 2.0.
132  
133 =cut
« blib/lib/Venus/Role/Doable.pm ↑ Summary blib/lib/Venus/Role/Tryable.pm »