Aion-Spirit

 view release on metacpan or  search on metacpan

t/aion/spirit.t  view on Meta::CPAN

use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
# 
# Aion::Spirit - functions for controlling the program execution process
# 
# # VERSION
# 
# 0.0.1
# 
# # SYNOPSIS
# 
subtest 'SYNOPSIS' => sub { 
use Aion::Spirit;

package A {
    sub x_1() { 1 }
    sub x_2() { 2 }
    sub y_1($) { 1+shift }
    sub y_2($) { 2+shift }
}

aroundsub "A", qr/_2$/, sub { shift->(@_[1..$#_]) + .03 };

::is scalar do {A::x_1}, scalar do{1}, 'A::x_1     # -> 1';

# Perl cached subroutines with prototype "()" in main:: as constant. aroundsub should be applied in a BEGIN block to avoid this:
::is scalar do {A::x_2}, scalar do{2}, 'A::x_2         # -> 2';
::is scalar do {(\&A::x_2)->()}, scalar do{2.03}, '(\&A::x_2)->() # -> 2.03';

# Functions with parameters not cached:
::is scalar do {A::y_1 .5}, scalar do{1.5}, 'A::y_1 .5  # -> 1.5';
::is scalar do {A::y_2 .5}, scalar do{2.53}, 'A::y_2 .5  # -> 2.53';

# 
# # DESCRIPTION
# 
# A Perl program consists of packages, globals, subroutines, lists, and scalars. That is, it is simply data that, unlike a C program, can be “changed on the fly.”
# 
# Thus, this module provides convenient functions for transforming all these entities, as well as maintaining their integrity.
# 
# # SUBROUTINES
# 
# ## aroundsub ($pkg, $re, $around)
# 
# Wraps the functions in the package in the specified regular sequence.
# 
# The package may not be specified for the current:
# 
# File N.pm:
#@> N.pm
#>> package N;
#>> 
#>> use Aion::Spirit qw/aroundsub/;
#>> 
#>> use constant z_2 => 10;
#>> 
#>> aroundsub qr/_2$/, sub { shift->(@_[1..$#_]) + .03 };
#>> 
#>> sub x_1() { 1 }
#>> sub x_2() { 2 }
#>> sub y_1($) { 1+shift }
#>> sub y_2($) { 2+shift }
#>> 
#>> 1;



( run in 1.761 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )