Skip to content

Commit

Permalink
testing trace()
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieb9 committed Feb 3, 2016
1 parent 70f1182 commit 34ca047
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Changes
@@ -1,9 +1,9 @@
Revision history for Wrap-Sub

0.06 2016-02-03
- renamed wrapped_state() to is_wrapped() (fixes #6)
- renamed wrapped_state() to is_wrapped() (closes #6)
- minor code cleanup
- POD rewrite
- POD rewrite (closes #4)

0.05 2016-02-02
- the parent wrap object now has a results() method, returns a list of
Expand Down
24 changes: 24 additions & 0 deletions examples/trace_entire_module.pl
@@ -0,0 +1,24 @@
#!/usr/bin/perl
use strict;
use warnings;

use lib 't/data';

use Devel::Trace::Subs qw(trace trace_dump);
use Three;
use Wrap::Sub;

$ENV{DTS_ENABLE} = 1;

my $pre = sub {
trace();
};

my $wrapper = Wrap::Sub->new(pre => $pre);
my $wrapped_subs = $wrapper->wrap('Three');

Three::one();

trace_dump();


5 changes: 2 additions & 3 deletions lib/Wrap/Sub.pm
Expand Up @@ -68,14 +68,13 @@ sub wrap {
push @subs, $sub;
}



my @children;

for my $sub (@subs) {
my $child = Wrap::Sub::Child->new;

$child->{wrapper} = $self; # allow parent capture of child sta
# allow parent capture of child sta
$child->{wrapper} = $self;

$child->pre($self->{pre}) if $self->{pre};

Expand Down
5 changes: 3 additions & 2 deletions lib/Wrap/Sub/Child.pm
Expand Up @@ -79,8 +79,9 @@ sub _wrap {
$post_return = [ $wrap->{post}->($pre_return, $sub_return) ];
}

push @{ $wrap->{wrapper}{post_returns} }, $post_return if defined $wrap->{post};

if (defined $wrap->{post}) {
push @{ $wrap->{wrapper}{post_returns} }, $post_return;
}
$post_return = undef if ! $wrap->{post_return};

if (! $wrap->{pre} && ! $wrap->{post}) {
Expand Down
6 changes: 4 additions & 2 deletions t/18-post_results.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
my $post_cref = sub {
my $pre_return = shift;
my $time = gettimeofday() - $pre_return->[0];
return "$Wrap::Sub::name finished in $time seconds\n";
return "$Wrap::Sub::name took $time seconds\n";
};

my $w = Wrap::Sub->new( pre => $pre_cref, post => $post_cref);
Expand All @@ -30,8 +30,10 @@ BEGIN {

my @results = $w->results;

is (@results, 8, "results() provides results");

for (@results){
like ($_->[0], qr/Three.*?finished/, "results() $_->[0] ok");
like ($_->[0], qr/Three.*?took/, "results() $_->[0] ok");
}

}
Expand Down

0 comments on commit 34ca047

Please sign in to comment.