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