File Coverage

lib/Aspect/Weaver.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package Aspect::Weaver;
2              
3 1     1   2658 use strict;
  1         3  
  1         46  
4 1     1   7 use warnings;
  1         1  
  1         31  
5 1     1   5 use Carp;
  1         2  
  1         67  
6 1     1   559 use Aspect::Hook::LexWrap;
  1         3  
  1         6  
7 1     1   8 use Devel::Symdump;
  1         2  
  1         319  
8              
9             my %UNTOUCHABLES = map { $_ => 1 } qw(
10             attributes base fields lib strict warnings Carp Carp::Heavy Config CORE
11             CORE::GLOBAL DB DynaLoader Exporter Exporter::Heavy IO IO::Handle UNIVERSAL
12             );
13              
14 10     10 0 1854 sub new { bless {}, shift }
15              
16             sub get_sub_names {
17             # TODO: need to filter Aspect exportable functions!
18 1910         366596 map { Devel::Symdump->new($_)->functions }
  2180         2548  
19 2360         2731 grep { !/^Aspect::/ }
20 10     10 0 353069 grep { !$UNTOUCHABLES{$_} }
21             Devel::Symdump->rnew->packages;
22             }
23              
24             sub install {
25 9     9 0 21 my ($self, $type, $sub_name, $code) = @_;
26 9 100       95 return wrap
27             $sub_name,
28             ($type eq 'before'? 'pre': 'post'),
29             $code;
30             }
31              
32             1;
33              
34             =head1 NAME
35              
36             Aspect::Weaver - aspect weaving functionality
37              
38             =head1 SYNOPSIS
39              
40             $weaver = Aspect::Weaver->new;
41             print join(',', $weaver->get_sub_names); # all wrappable subs
42             $weaver->install(before => 'Employee::get_name', $wrapper_code);
43             $weaver->install(after => 'Employee::set_name', $wrapper_code);
44              
45             =head1 DESCRIPTION
46              
47             Used by L to get all wrappable subs, and to install a
48             before/after hook on a sub. Uses L for the
49             wrapping itself, and C for accessing symbol table info.
50              
51             =head1 SEE ALSO
52              
53             See the L pod for a guide to the Aspect module.
54              
55             =cut