NAME
Venus::Role::Patchable - Patchable Role
ABSTRACT
Patchable Role for Perl 5
SYNOPSIS
package
Example;
use
Venus::Class;
package
main;
my
$example
= Example->new;
# my $patch = $example->patch;
# bless(.., "Venus::Space")
DESCRIPTION
This package modifies the consuming package and provides methods for patching (or monkey-patching) routines in the calling package using "patch" in Venus::Space.
METHODS
This package provides the following methods:
patch
patch(string
$name
, coderef
$code
) (Venus::Space)
The patch method overwrites the named subroutine in the calling package using "patch" in Venus::Space returning a Venus::Space object that can be used to restore the original subroutine when "unpatch" in Venus::Space is called.
Since 3.55
- patch example 1
-
package
Example;
use
Venus::Class;
sub
test {
my
(
$self
,
@args
) =
@_
;
return
[
$self
,
@args
];
}
package
main;
my
$example
= Example->new;
my
$patch
=
$example
->patch(
'test'
,
sub
{
my
(
$next
,
@args
) =
@_
;
return
[
'patched'
, @{
$next
->(
@args
)}];
});
# bless(.., "Venus::Space")
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2022, Awncorp, awncorp@cpan.org
.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.