Devel-Events
view release on metacpan or search on metacpan
lib/Devel/Events/Generator/SubTrace.pm view on Meta::CPAN
my @ret;
my $ret;
my $tsub ="$sub";
$tsub = 'main' unless $tsub;
my @args = (
'name' => "$tsub",
'code' => \&$tsub,
'args' => [ @_ ],
'depth' => $DEPTH,
'wantarray' => wantarray(),
);
push @args, autoload => do { no strict 'refs'; $$tsub }
if (( length($tsub) > 10) && (substr( $tsub, -10, 10 ) eq '::AUTOLOAD' ));
$SINGLETON->enter_sub(@args);
{
no strict 'refs';
if (wantarray) {
@ret = &$sub;
}
elsif (defined wantarray) {
$ret = &$sub;
}
else {
&$sub;
}
}
$SINGLETON->leave_sub(
@args,
ret => (wantarray) ? \@ret : defined(wantarray) ? $ret : undef,
);
return (wantarray) ? @ret : defined(wantarray) ? $ret : undef;
}
}
sub enter_sub {
my ( $self, @data ) = @_;
local $IGNORE = 1;
$self->send_event( enter_sub => @data );
}
sub leave_sub {
my ( $self, @data ) = @_;
local $IGNORE = 1;
$self->send_event( leave_sub => @data );
}
sub enable {
my $self = shift;
local $IGNORE = 1;
$SINGLETON = $self;
Scalar::Util::weaken($SINGLETON);
}
sub disable {
$SINGLETON = undef;
}
__PACKAGE__;
__END__
=pod
=encoding UTF-8
=head1 NAME
Devel::Events::Generator::SubTrace - generate C<executing_line> events using the perl debugger api
=head1 VERSION
version 0.10
=head1 SYNOPSIS
my $g = Devel::Events::Generator::SubTrace->new( handler => $h );
$g->enable();
# every subroutine will have two events fired, on entry and exit
$g->disable();
=head1 DESCRIPTION
This L<Devel::Events> generator will fire sub tracing events using C<DB::sub>,
a perl debugger hook.
Only one instance may be enabled at a given time. Use
L<Devel::Events::Handler::Multiplex> to deliver events to multiple handlers.
Subroutines inside the L<Devel::Events> namespace or it's children will be
skipped.
=head1 EVENTS
=over 4
=item enter_sub
When the generator is enabled, this event will fire for every subroutine, just
before it is executed.
Subroutines in a package starting with C<Devel::Events::> will not be reported.
=over 4
=item name
The name of the subroutine (or it's C<overload::StrVal> if it has none).
( run in 1.111 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )