| 1 | package Devel::Spy; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Devel::Spy::Util; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Sub::Name (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | ▶ | use Devel::Spy::_constants; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | our $VERSION = '0.07'; | ||
| 10 | |||
| 11 | 0 | ▶ | sub new { |
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||
| 12 | 0 | my @self; | |
| 13 | |||
| 14 | # Store a tied wrapper over the object. This will be used anytime | ||
| 15 | # thing is ever used as a value or reference. | ||
| 16 | 0 | $self[TIED_PAYLOAD] = Devel::Spy::Util->wrap_thing( $_[_thing], $_[_logger] ); | |
| 17 | |||
| 18 | # Store a plain copy of $thing as well. If $thing is an object the | ||
| 19 | # method calls have to go through this copy instead. tied objects | ||
| 20 | # can't be returned as objects from function calls. | ||
| 21 | 0 | $self[UNTIED_PAYLOAD] = $_[_thing]; | |
| 22 | |||
| 23 | # Store the reporting code, whatever that is. | ||
| 24 | 0 | $self[CODE] = $_[_logger]; | |
| 25 | |||
| 26 | 0 | return bless \@self, "$_[_class]\::_obj"; | |
| 27 | } | ||
| 28 | |||
| 29 | my $null_eventlog = Devel::Spy::Util->Y( | ||
| 30 | Sub::Name::subname( null_eventlog_curry => sub { | ||
| 31 | my $f = shift @_; | ||
| 32 | return Sub::Name::subname( null_eventlog => sub { | ||
| 33 | return $f; | ||
| 34 | } ); | ||
| 35 | } ) | ||
| 36 | ); | ||
| 37 | |||
| 38 | 0 | ▶ | sub make_null_eventlog { |
|
Subroutine
make_null_eventlog: not called CC=1 SCAR=6.9
| |||
| 39 | 0 | return $null_eventlog; | |
| 40 | } | ||
| 41 | |||
| 42 | 0 | ▶ | sub make_eventlog { |
|
Subroutine
make_eventlog: not called CC=1 SCAR=6.9
| |||
| 43 | |||
| 44 | # C<make_eventlog> returns a closure which appends a new element to a | ||
| 45 | # log and returns a closure which appends to the new log entry. | ||
| 46 | # | ||
| 47 | # my ( $log, $logger ) = Devel::Spy->make_eventlog; | ||
| 48 | # | ||
| 49 | # my $foo = $logger->log( 'A' ); # pushes 'A' onto @$log | ||
| 50 | # $foo = $foo->( 'B' ); # Appends 'B' to 'A' | ||
| 51 | # $foo = $foo->( 'C' ); # Appends 'C' to 'AB' | ||
| 52 | # $foo = $foo->( 'D' ); # Appends 'D' to 'ABC' | ||
| 53 | # | ||
| 54 | # my $bar = $logger->log( 1 ) # pushes '1' onto @$log | ||
| 55 | # $bar = $bar->( 2 ); # Appends '2' onto '1' | ||
| 56 | # $bar = $bar->( 3 ); # Appends '3' onto '12' | ||
| 57 | # $bar = $bar->( 4 ); # Appends '4' onto '123' | ||
| 58 | |||
| 59 | 0 | my @eventlog; | |
| 60 | 0 | ▶ | my $logger = Sub::Name::subname( EVENT => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 61 | |||
| 62 | # Add to the event log | ||
| 63 | 0 | push @eventlog, "@_"; | |
| 64 | |||
| 65 | # Let the caller add more information to this log entry | ||
| 66 | # with more information as needed. | ||
| 67 | 0 | my $followup = \$eventlog[-1]; | |
| 68 | return Devel::Spy::Util->Y( | ||
| 69 | 0 | ▶ | Sub::Name::subname( eventlog_curry => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 70 | 0 | my $f = shift @_; | |
| 71 | 0 | ▶ | Sub::Name::subname( eventlog_followup => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 72 | 0 | $$followup .= "@_"; | |
| 73 | 0 | $f; | |
| 74 | 0 | } ); | |
| 75 | } | ||
| 76 | 0 | ) ); | |
| 77 | 0 | } ); | |
| 78 | |||
| 79 | 0 | return ( \@eventlog, $logger ); | |
| 80 | } | ||
| 81 | |||
| 82 | my $tattler = Devel::Spy::Util->Y( | ||
| 83 | Sub::Name::subname( tattler_curry => sub { | ||
| 84 | my $f = shift @_; | ||
| 85 | return Sub::Name::subname( tattler => sub { | ||
| 86 | local $\ = "\n"; | ||
| 87 | print for @_; | ||
| 88 | return $f; | ||
| 89 | } ); | ||
| 90 | } | ||
| 91 | ) ); | ||
| 92 | |||
| 93 | 0 | ▶ | sub make_tattler { |
|
Subroutine
make_tattler: not called CC=1 SCAR=6.9
| |||
| 94 | 0 | return $tattler; | |
| 95 | } | ||
| 96 | |||
| 97 | # Include these *after* _compile is compiled because they'll want it available. | ||
| 98 | 0 | ▶ | use Devel::Spy::_obj; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 99 | use Devel::Spy::TieScalar; | ||
| 100 | use Devel::Spy::TieArray; | ||
| 101 | use Devel::Spy::TieHash; | ||
| 102 | use Devel::Spy::TieHandle; | ||
| 103 | |||
| 104 | our $DEBUG; | ||
| 105 | |||
| 106 | 1; | ||
| 107 | |||
| 108 | __END__ | ||