[Jifty-commit] r5428 - in Runops-Hook/trunk: . lib/Runops

Jifty commits jifty-commit at lists.jifty.org
Sat May 10 08:52:20 EDT 2008


Author: nothingmuch
Date: Sat May 10 08:52:20 2008
New Revision: 5428

Added:
   Runops-Hook/trunk/Trace.xs
      - copied, changed from r5427, /Runops-Hook/trunk/Hook.xs
   Runops-Hook/trunk/lib/Runops/Trace.pm
      - copied, changed from r5391, /Runops-Hook/trunk/lib/Runops/Hook.pm
   Runops-Hook/trunk/t/03even.t
Removed:
   Runops-Hook/trunk/Hook.xs
   Runops-Hook/trunk/lib/Runops/Hook.pm
Modified:
   Runops-Hook/trunk/Changes
   Runops-Hook/trunk/Makefile.PL
   Runops-Hook/trunk/t/01compile.t
   Runops-Hook/trunk/t/02mapstart.t
   Runops-Hook/trunk/t/03given.t
   Runops-Hook/trunk/t/04features.t
   Runops-Hook/trunk/t/05printtofh.t
   Runops-Hook/trunk/t/06counters.t
   Runops-Hook/trunk/t/07perl_Hook.t
   Runops-Hook/trunk/t/08fact.t

Log:
finish Runops::Trace merge

Modified: Runops-Hook/trunk/Changes
==============================================================================
--- Runops-Hook/trunk/Changes	(original)
+++ Runops-Hook/trunk/Changes	Sat May 10 08:52:20 2008
@@ -1,6 +1,44 @@
-0.02
-	- Perl space hooking FTW!!!11one
-	- Introduced many new opportunities for segfaults
+0.01 - Thu Oct  6 01:35:32 UTC 2005
+    First version, based on RGS's Runops::Switch.
 
-0.01
-    First version.
+0.02 - Sun Jun 17              2007
+    Patched from chromatic's for my own used.
+
+0.03 - Mon Jun 18              2007
+    Finished initial distribution.
+    Added functions:
+     - Runops::Trace->trace( TRACE, CODE )
+     - trace_code( CODE )
+     - checksum_code_path( CODE )
+
+0.04 - Thu Jun 21              2007
+    Ought to build on threaded perls
+    Traps die() now.
+
+0.05 - Thu Jun 21              2007
+    Actually require Digest::MD5
+
+0.06 - Sun Jun 24              2007
+    Pre-YAPC release
+    trace wasn't exportable, now it is.
+
+0.07 - Wed Aug  1              2007
+    Speed.
+    API Change.
+
+      The trace callback recieves only the numeric pointer of the op
+      now. Future versions will be given a B::OP object. ATM,
+      marshalling the pointer to a B::OP object is your
+      responsibility.
+
+      The number is also the same scalar all the time. References
+      taken to it will only reflect the last used value.
+
+0.08 - Thu Aug  2              2007
+    Just PAUSE fluff. This is the same as 0.07
+
+0.09 - Thu Aug  2              2007
+    Document requirement for 5.8.0.
+
+0.10
+    Merged in Runops::Hook

Modified: Runops-Hook/trunk/Makefile.PL
==============================================================================
--- Runops-Hook/trunk/Makefile.PL	(original)
+++ Runops-Hook/trunk/Makefile.PL	Sat May 10 08:52:20 2008
@@ -5,6 +5,6 @@
 use ExtUtils::MakeMaker;
 
 WriteMakefile(
-    NAME		=> 'Runops::Hook',
-    VERSION_FROM	=> 'lib/Runops/Hook.pm',
+    NAME		=> 'Runops::Trace',
+    VERSION_FROM	=> 'lib/Runops/Trace.pm',
 );

Copied: Runops-Hook/trunk/Trace.xs (from r5427, /Runops-Hook/trunk/Hook.xs)
==============================================================================
--- /Runops-Hook/trunk/Hook.xs	(original)
+++ Runops-Hook/trunk/Trace.xs	Sat May 10 08:52:20 2008
@@ -6,22 +6,22 @@
 
 #define XPUSHREF(x) XPUSHs(sv_2mortal(newRV_inc(x)))
 
-int (*Runops_Hook_old_runops ) ( pTHX );
+int (*Runops_Trace_old_runops ) ( pTHX );
 
-bool (*Runops_Hook_hook)(pTHX);
+bool (*Runops_Trace_hook)(pTHX);
 
-static HV *Runops_Hook_op_counters;
+static HV *Runops_Trace_op_counters;
 
-static bool Runops_Hook_enabled;
-static UV Runops_Hook_threshold = 0;
+static bool Runops_Trace_enabled;
+static UV Runops_Trace_threshold = 0;
 
-static SV *Runops_Hook_perl_hook;
-static bool Runops_Hook_perl_ignore_ret = 1;
+static SV *Runops_Trace_perl_hook;
+static bool Runops_Trace_perl_ignore_ret = 1;
 
-static bool Runops_Hook_loaded_B;
-static GV *Runops_Hook_B_UNOP_stash;
-static UNOP Runops_Hook_fakeop;
-static SV *Runops_Hook_fakeop_sv;
+static bool Runops_Trace_loaded_B;
+static GV *Runops_Trace_B_UNOP_stash;
+static UNOP Runops_Trace_fakeop;
+static SV *Runops_Trace_fakeop_sv;
 
 #define ARITY_NULL 0
 #define ARITY_UNARY 1
@@ -37,9 +37,9 @@
   while (PL_op) {
 
     /* global flag controls all hooking behavior */
-    if (Runops_Hook_enabled) {
+    if (Runops_Trace_enabled) {
       /* no threshold set means simple hooking */
-      if (Runops_Hook_hook && CALL_FPTR( Runops_Hook_hook) (aTHX))
+      if (Runops_Trace_hook && CALL_FPTR( Runops_Trace_hook) (aTHX))
         continue;
     }
 
@@ -54,19 +54,19 @@
 }
 
 void
-Runops_Hook_enable () {
-  Runops_Hook_enabled = 1;
+Runops_Trace_enable () {
+  Runops_Trace_enabled = 1;
 }
 
 void
-Runops_Hook_disable () {
-  Runops_Hook_enabled = 0;
+Runops_Trace_disable () {
+  Runops_Trace_enabled = 0;
 }
 
 SV *
-Runops_Hook_op_to_BOP (pTHX_ OP *op) {
+Runops_Trace_op_to_BOP (pTHX_ OP *op) {
   dSP;
-  /* this assumes Runops_Hook_load_B() has already been called */
+  /* this assumes Runops_Trace_load_B() has already been called */
 
   /* we fake B::UNOP object (fakeop_sv) that points to our static fakeop.
    * then we set first_op to the op we want to make an object out of, and
@@ -75,10 +75,10 @@
    * B should really have a way to create an op from a pointer via some
    * external API. This sucks monkey balls on olympic levels */
 
-  Runops_Hook_fakeop.op_first = op;
+  Runops_Trace_fakeop.op_first = op;
 
   PUSHMARK(SP);
-  XPUSHs(Runops_Hook_fakeop_sv);
+  XPUSHs(Runops_Trace_fakeop_sv);
   PUTBACK;
 
   call_pv("B::UNOP::first", G_SCALAR);
@@ -89,7 +89,7 @@
 }
 
 IV
-Runops_Hook_op_arity (pTHX_ OP *o) {
+Runops_Trace_op_arity (pTHX_ OP *o) {
   switch (o->op_type) {
     case OP_SASSIGN:
       /* wtf? */
@@ -149,7 +149,7 @@
 
 /* this is a hook that calls to a perl code ref */
 bool
-Runops_Hook_perl (pTHX) {
+Runops_Trace_perl (pTHX) {
   dSP;
 
   register SV **orig_sp = SP;
@@ -160,39 +160,39 @@
   bool ret;
   IV arity;
 
-  if (Runops_Hook_threshold != 0) {
+  if (Runops_Trace_threshold != 0) {
     /* having a threshold means that only ops that are hit enough
      * times get hooked, the idea is that this can be used for
      * trace caching */
 
-    if ( !Runops_Hook_op_counters )
-      Runops_Hook_op_counters = newHV();
+    if ( !Runops_Trace_op_counters )
+      Runops_Trace_op_counters = newHV();
 
     /* unfortunately we need to keep the counters in a hash */
-    SV **count = hv_fetch(Runops_Hook_op_counters, (char *)PL_op, sizeof(PL_op), 1);
+    SV **count = hv_fetch(Runops_Trace_op_counters, (char *)PL_op, sizeof(PL_op), 1);
     UV c       = SvTRUE(*count) ? SvUV(*count) + 1 : 1;
     sv_setuv(*count, c);
 
     /* if we haven't reached the threshold yet, then return */
-    if (c < Runops_Hook_threshold)
+    if (c < Runops_Trace_threshold)
       return 0;
   }
 
   /* don't want to hook the hook */
-  Runops_Hook_disable();
+  Runops_Trace_disable();
 
   /* make the environment as normal as possible for callbacks */
-  PL_runops = Runops_Hook_old_runops;
+  PL_runops = Runops_Trace_old_runops;
 
   ENTER;
   SAVETMPS;
 
-  PL_op_object = Runops_Hook_op_to_BOP(aTHX_ PL_op);
-  arity = Runops_Hook_op_arity(aTHX_ PL_op);
+  PL_op_object = Runops_Trace_op_to_BOP(aTHX_ PL_op);
+  arity = Runops_Trace_op_arity(aTHX_ PL_op);
 
 
   PUSHMARK(SP);
-  XPUSHs(Runops_Hook_perl_hook);
+  /* XPUSHs(Runops_Trace_perl_hook); */
   XPUSHs(PL_op_object);
   XPUSHs(sv_2mortal(newSViv(arity)));
 
@@ -248,14 +248,14 @@
 
   PUTBACK;
 
-  call_sv(Runops_Hook_perl_hook, (Runops_Hook_perl_ignore_ret ? G_DISCARD : G_SCALAR));
+  call_sv(Runops_Trace_perl_hook, (Runops_Trace_perl_ignore_ret ? G_DISCARD : G_SCALAR));
 
   SPAGAIN;
 
   /* we coerce it here so that SvTRUE is evaluated without hooking, and
-   * Runops_Hook_enable() is the last thing in this hook */
+   * Runops_Trace_enable() is the last thing in this hook */
 
-  if (!Runops_Hook_perl_ignore_ret) {
+  if (!Runops_Trace_perl_ignore_ret) {
     sv_ret = POPs;
     ret = SvTRUE(sv_ret);
   } else {
@@ -270,87 +270,87 @@
   /* set up debugging again */
   PL_runops = runops_trace;
 
-  Runops_Hook_enable();
+  Runops_Trace_enable();
 
   return ret;
 }
 
 void
-Runops_Hook_clear_hook () {
-  Runops_Hook_hook = NULL;
+Runops_Trace_clear_hook () {
+  Runops_Trace_hook = NULL;
 }
 
 void
-Runops_Hook_set_hook (bool (*hook)(pTHX)) {
-  Runops_Hook_hook = hook;
+Runops_Trace_set_hook (bool (*hook)(pTHX)) {
+  Runops_Trace_hook = hook;
 }
 
 void
-Runops_Hook_clear_perl_hook(pTHX) {
-  if ( Runops_Hook_perl_hook != (SV*)NULL ) {
-    SvSetSV(Runops_Hook_perl_hook, &PL_sv_undef );
+Runops_Trace_clear_perl_hook(pTHX) {
+  if ( Runops_Trace_perl_hook != (SV*)NULL ) {
+    SvSetSV(Runops_Trace_perl_hook, &PL_sv_undef );
   }
 }
 
 void
-Runops_Hook_load_B (pTHX) {
-  if (!Runops_Hook_loaded_B) {
+Runops_Trace_load_B (pTHX) {
+  if (!Runops_Trace_loaded_B) {
     load_module( PERL_LOADMOD_NOIMPORT, newSVpv("B", 0), newSViv(0) );
-    Runops_Hook_fakeop_sv = sv_bless(newRV_noinc(newSVuv((UV)&Runops_Hook_fakeop)), gv_stashpv("B::UNOP", 0));
-    Runops_Hook_loaded_B = 1;
+    Runops_Trace_fakeop_sv = sv_bless(newRV_noinc(newSVuv((UV)&Runops_Trace_fakeop)), gv_stashpv("B::UNOP", 0));
+    Runops_Trace_loaded_B = 1;
   }
 }
 
 void
-Runops_Hook_set_perl_hook (pTHX_ SV *tracer_rv) {
+Runops_Trace_set_perl_hook (pTHX_ SV *tracer_rv) {
   /* Validate tracer_rv */
   if ( ! SvROK( tracer_rv ) ||  ! SVt_PVCV == SvTYPE( SvRV( tracer_rv ) ) ) {
-    croak( aTHX_ "the hook must be a code reference" );
+    croak("the hook must be a code reference");
   }
 
-  Runops_Hook_clear_perl_hook(aTHX);
+  Runops_Trace_clear_perl_hook(aTHX);
 
-  Runops_Hook_load_B(aTHX);
+  Runops_Trace_load_B(aTHX);
 
   /* Initialize/set the tracing function */
-  if ( Runops_Hook_perl_hook == (SV*)NULL ) {
-    Runops_Hook_perl_hook = newSVsv( tracer_rv );
+  if ( Runops_Trace_perl_hook == (SV*)NULL ) {
+    Runops_Trace_perl_hook = newSVsv( tracer_rv );
   }
   else {
-    SvSetSV( Runops_Hook_perl_hook, tracer_rv );
+    SvSetSV( Runops_Trace_perl_hook, tracer_rv );
   }
 
-  Runops_Hook_set_hook(Runops_Hook_perl);
+  Runops_Trace_set_hook(Runops_Trace_perl);
 }
 
 UV
-Runops_Hook_get_threshold () {
-  return Runops_Hook_threshold;
+Runops_Trace_get_threshold () {
+  return Runops_Trace_threshold;
 }
 
 void
-Runops_Hook_set_threshold (UV t) {
-  Runops_Hook_threshold = t;
+Runops_Trace_set_threshold (UV t) {
+  Runops_Trace_threshold = t;
 }
 
 
-MODULE = Runops::Hook PACKAGE = Runops::Hook
+MODULE = Runops::Trace PACKAGE = Runops::Trace
 
 PROTOTYPES: ENABLE
 
 BOOT:
-  Runops_Hook_clear_hook();
-  Runops_Hook_old_runops = PL_runops;
+  Runops_Trace_clear_hook();
+  Runops_Trace_old_runops = PL_runops;
   PL_runops = runops_trace;
 
 HV *
 counters()
   CODE:
 {
-  if ( !Runops_Hook_op_counters )
-    Runops_Hook_op_counters = newHV();
+  if ( !Runops_Trace_op_counters )
+    Runops_Trace_op_counters = newHV();
 
-  RETVAL = Runops_Hook_op_counters;
+  RETVAL = Runops_Trace_op_counters;
 }
   OUTPUT:
     RETVAL
@@ -359,7 +359,7 @@
 enabled()
   CODE:
 {
-  RETVAL = Runops_Hook_enabled;
+  RETVAL = Runops_Trace_enabled;
 }
   OUTPUT:
     RETVAL
@@ -368,21 +368,21 @@
 enable()
   CODE:
 {
-  Runops_Hook_enable();
+  Runops_Trace_enable();
 }
 
 void
 disable()
   CODE:
 {
-  Runops_Hook_disable();
+  Runops_Trace_disable();
 }
 
 UV
 get_threshold()
   CODE:
 {
-  RETVAL = Runops_Hook_get_threshold();
+  RETVAL = Runops_Trace_get_threshold();
 }
   OUTPUT:
     RETVAL
@@ -391,36 +391,36 @@
 set_threshold(SV *a)
     CODE:
 {
-     Runops_Hook_set_threshold(SvUV(a));
+     Runops_Trace_set_threshold(SvUV(a));
 }
 
 void
 set_hook(SV *hook)
   CODE:
 {
-  Runops_Hook_set_perl_hook(aTHX_ hook);
+  Runops_Trace_set_perl_hook(aTHX_ hook);
 }
 
 void
 clear_hook()
   CODE:
 {
-  Runops_Hook_clear_perl_hook(aTHX);
-  Runops_Hook_clear_hook();
+  Runops_Trace_clear_perl_hook(aTHX);
+  Runops_Trace_clear_hook();
 }
 
 void
 ignore_hook_ret()
   CODE:
 {
-  Runops_Hook_perl_ignore_ret = 1;
+  Runops_Trace_perl_ignore_ret = 1;
 }
 
 void
 unignore_hook_ret()
   CODE:
 {
-  Runops_Hook_perl_ignore_ret = 0;
+  Runops_Trace_perl_ignore_ret = 0;
 }
 
 void
@@ -429,24 +429,24 @@
     SV * to_trace_rv
   PROTOTYPE: $$
   CODE:
-    Runops_Hook_set_perl_hook( aTHX_ tracer_rv );
+    Runops_Trace_set_perl_hook( aTHX_ tracer_rv );
 
     /* Call the function to trace */
-    Runops_Hook_enable();
+    Runops_Trace_enable();
     call_sv( to_trace_rv, G_VOID | G_DISCARD | G_EVAL | G_KEEPERR );
-    Runops_Hook_disable();
+    Runops_Trace_disable();
 
 void
 enable_global_tracing(tracer_rv)
     SV * tracer_rv
   PROTOTYPE: $
   CODE:
-    Runops_Hook_set_perl_hook( aTHX_ tracer_rv );
-    Runops_Hook_enable();
+    Runops_Trace_set_perl_hook( aTHX_ tracer_rv );
+    Runops_Trace_enable();
 
 void
 disable_global_tracing()
   PROTOTYPE:
   CODE:
-    Runops_Hook_disable();
+    Runops_Trace_disable();
 

Copied: Runops-Hook/trunk/lib/Runops/Trace.pm (from r5391, /Runops-Hook/trunk/lib/Runops/Hook.pm)
==============================================================================
--- /Runops-Hook/trunk/lib/Runops/Hook.pm	(original)
+++ Runops-Hook/trunk/lib/Runops/Trace.pm	Sat May 10 08:52:20 2008
@@ -1,98 +1,150 @@
-package Runops::Hook;
+package Runops::Trace;
 
 use strict;
 use warnings;
+use Digest::MD5 ();
+use File::Spec  ();
 
-our $VERSION = '0.02';
+our $VERSION = '0.09';
 
 use DynaLoader ();
-our @ISA = qw(DynaLoader);
-__PACKAGE__->bootstrap;
+our @ISA = qw( DynaLoader Exporter );
+Runops::Trace->bootstrap($VERSION);
 
-sub import {
-	my ( $class, @args ) = @_;
+our @EXPORT_OK = qw( trace_code checksum_code_path trace );
+our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
 
-	if ( @args == 1 and ref($args[0]) ) {
-		set_hook($args[0]);
-		enable();
-	}
+sub checksum_code_path {
+    my ($f) = @_;
+
+    # Preallocate a 2**19 byte long string. See
+    # http://perlmonks.org/?node_id=630323
+    open my $nul, '<', File::Spec->devnull;
+    my $ops = '';
+    sysread $nul, $ops, 2**19, 0;
+
+    # Just stash the pointers.
+    _trace_function( sub { $ops .= { $_[0] || return } }, $f );
+
+    return Digest::MD5::md5_hex($ops);
+}
+
+sub trace_code {
+    my ($f) = @_;
+    my @ops;
+    _trace_function( sub { push @ops, $_[0] }, $f );
+
+    return wantarray ? @ops : join "\n", @ops;
+}
+
+sub trace {
+    my ( $tracer, $callback ) = @_;
+
+    _trace_function( $tracer, $callback );
+    return;
 }
 
 1;
 
 __END__
 
-=pod
-
 =head1 NAME
 
-Runops::Hook - Hook the runloop to a C or Perl callback
+Runops::Trace - Trace your program's execution
 
 =head1 SYNOPSIS
 
-	use Runops::Hook;
+  use Runops::Trace 'checksum_code_path';
+  sub is_even { shift() % 2 == 0 ? 1 : 0 }
 
-	Runops::Hook::set_hook(sub {
-		my ( $hook, $op, $arity, @args ) = @_;
-		# $hook is the hook coderef
-		# $op is the B::OP object representing PL_op
-		# $arity is a value describing what to expect in @args
-		# @args are the arguments to the operator passed by scalar reference
-	});
+  my %sufficient;
+  for my $number ( 0 .. 10 ) {
+      # Get a signature for the code 
+      my $codepath = checksum_code_path(
+          sub { is_even( $number ) }
+      );
 
-	Runops::Hook::enable();
+      if ( not exists $sufficient{$codepath} ) {
+          $sufficient{$codepath} = $number;
+      }
+  }
+  print join ' ', keys %sufficient;
 
-	# code from here on is traced
+=head1 DESCRIPTION
 
-	Runops::Hook::disable(); # tracing stops just after entersub for 'disable' itself
+This module traces opcodes as they are executed by the perl VM. The
+trace function can be turned on globally or just during the execution
+of a single function.
 
-If you are concerned about your callback's performance you can register a C
-callback too.
+=head1 INTERFACE
 
-	# in MyHook.xs
-	bool
-	my_hook (pTHX) {
-		/* you can play with PL_op here */
+=over
 
-		/* returning a true value will skip the pp_addr call,
-		 * letting the hook override the whole runloop */
+=item trace( TRACE, FUNCTION )
 
-		return 0; /* resume the loop normally */
-	}
+This is a generic way of tracing a function. It ensures that your
+C<TRACE> function is called before every operation in the C<FUNCTION>
+function.
 
-	MODULE = MyHook PACKAGE MyHook
-	BOOT:
-		Runops_Hook_set_hook(my_hook);
-		Runops_Hook_enable();
+The C<TRACE> function will be given the pointer of the opnode that is
+about to be run. This is an interim API. The desired result is that a
+B::OP object is passed instead of just the pointer. Also, it is always
+the same scalar - only the value is changing. References taken to this
+value will mutate. The C<TRACE> function will be called in void
+context.
 
-=head1 STATUS
+The C<FUNCTION> function will be called in void context and will not
+be given any parameters.
 
-This is still very much experimental and in need of usability improvements,
-docs, tests, etc.
+There is no useful return value from this function.
 
-It's released for amusement/embarrassment purposes only ;-)
+=item MD5SUM = checksum_code_path( FUNCTION )
 
-=head1 HOOKS
+This returns a hex MD5 checksum of the ops that were visited. This is
+a nice, concise way of representing a unique path through code.
 
-The runloop has a global boolean, C<Runops_Hook_enabled>. When unset, the
-runloop works like the normal Perl run loop.
+=item STRING = trace_code( FUNCTION )
 
-When the flag is enabled and C<Runops_Hook_threshold> is 0 (the default) then
-the hook will be called on every loop iteration.
+This returns a string representing the ops that were executed. Each op
+is represented as its name and hex address in memory.
 
-If C<Runops_Hook_threshold> is set to a non zero value then the hook will only
-be called when an op counter C<PL_op> has reached the threshold.
+=back
 
-=head1 AUTHOR
+=head1 PERL HACKS COMPATIBILITY
 
-Chia-Liang Kao E<lt>clkao at clkao.orgE<gt>
+This module does not currently implement the interface as described in
+the O'Reilly book Perl Hacks.
 
-Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
+=head1 ADVANCED NOTES
+
+=over
+
+=item THREAD-UNSAFE
+
+I made no attempt at thread safety. Do not use this module in a
+multi-threaded process.
+
+=item WRITE YOUR OWN SUGAR
+
+The C<trace( TRACE, FUNCTION )> function is sufficient to allow any
+arbitrary kind of access to running code. This module is included with
+two simple functions to return useful values. Consider looking at
+their source code and writing your own.
+
+=item ON THE FLY CODE MODIFICATION
+
+If the L<B::Generate> module is loaded, the B:: object that is passed
+to the tracing function may also be modified. This would allow you to
+modify the perl program as it is running. Thi
+
+=back
+
+=head1 AUTHOR
 
-=head1 COPYRIGHT
+Rewritten by Joshua ben Jore, originally written by chromatic, based
+on L<Runops::Switch> by Rafael Garcia-Suarez.
 
-	Copyright (c) 2008 Chia-Liang Kao, Yuval Kogman. All rights
-	reserved. This program is free software; you can redistribute
-	it and/or modify it under the same terms as Perl itself.
+This program is free software; you may redistribute it and/or modify
+it under the same terms as Perl 5.8.x itself.
 
 =cut

Modified: Runops-Hook/trunk/t/01compile.t
==============================================================================
--- Runops-Hook/trunk/t/01compile.t	(original)
+++ Runops-Hook/trunk/t/01compile.t	Sat May 10 08:52:20 2008
@@ -2,8 +2,8 @@
 
 use Test::More tests => 4;
 
-use_ok('Runops::Hook');
-Runops::Hook::enable();
+use_ok('Runops::Trace');
+Runops::Trace::enable();
 
 pass('and it continues to work');
 eval  { pass('... in eval {}') };

Modified: Runops-Hook/trunk/t/02mapstart.t
==============================================================================
--- Runops-Hook/trunk/t/02mapstart.t	(original)
+++ Runops-Hook/trunk/t/02mapstart.t	Sat May 10 08:52:20 2008
@@ -1,7 +1,7 @@
 #!perl
 
-use Runops::Hook;
-BEGIN { Runops::Hook::enable() }
+use Runops::Trace;
+BEGIN { Runops::Trace::enable() }
 
 use Test::More tests => 1;
 

Added: Runops-Hook/trunk/t/03even.t
==============================================================================
--- (empty file)
+++ Runops-Hook/trunk/t/03even.t	Sat May 10 08:52:20 2008
@@ -0,0 +1,13 @@
+use Test::More tests => 3;
+use Runops::Trace 'checksum_code_path';
+
+sub is_even { $_[0] % 2 == 0 ? 'even' : 'odd' }
+
+my @paths;
+for my $i ( 0 .. 3 ) {
+    $paths[$i] = checksum_code_path( sub { is_even($i) } );
+}
+
+is( $paths[0], $paths[2] );
+is( $paths[1], $paths[3] );
+isnt( $paths[0], $paths[1] );

Modified: Runops-Hook/trunk/t/03given.t
==============================================================================
--- Runops-Hook/trunk/t/03given.t	(original)
+++ Runops-Hook/trunk/t/03given.t	Sat May 10 08:52:20 2008
@@ -3,8 +3,8 @@
 use strict;
 use warnings;
 
-use Runops::Hook;
-BEGIN { Runops::Hook::enable() }
+use Runops::Trace;
+BEGIN { Runops::Trace::enable() }
 
 use Test::More;
 

Modified: Runops-Hook/trunk/t/04features.t
==============================================================================
--- Runops-Hook/trunk/t/04features.t	(original)
+++ Runops-Hook/trunk/t/04features.t	Sat May 10 08:52:20 2008
@@ -3,8 +3,8 @@
 use strict;
 use warnings;
 
-use Runops::Hook;
-BEGIN { Runops::Hook::enable() }
+use Runops::Trace;
+BEGIN { Runops::Trace::enable() }
 
 use Test::More;
 

Modified: Runops-Hook/trunk/t/05printtofh.t
==============================================================================
--- Runops-Hook/trunk/t/05printtofh.t	(original)
+++ Runops-Hook/trunk/t/05printtofh.t	Sat May 10 08:52:20 2008
@@ -2,8 +2,8 @@
 
 use strict;
 use warnings;
-use Runops::Hook;
-BEGIN { Runops::Hook::enable() }
+use Runops::Trace;
+BEGIN { Runops::Trace::enable() }
 
 use Test::More tests => 1;
 

Modified: Runops-Hook/trunk/t/06counters.t
==============================================================================
--- Runops-Hook/trunk/t/06counters.t	(original)
+++ Runops-Hook/trunk/t/06counters.t	Sat May 10 08:52:20 2008
@@ -3,26 +3,26 @@
 use strict;
 use warnings;
 
-use Runops::Hook;
+use Runops::Trace;
 use Test::More 'no_plan';
 
-ok( !Runops::Hook::enabled(), "disabled" );
+ok( !Runops::Trace::enabled(), "disabled" );
 
-Runops::Hook::set_hook(sub {});
+Runops::Trace::set_hook(sub {});
 
-is_deeply( Runops::Hook::counters(), {}, "no counters yet" );
+is_deeply( Runops::Trace::counters(), {}, "no counters yet" );
 
-Runops::Hook::enable();
+Runops::Trace::enable();
 
-Runops::Hook::set_threshold(3);
+Runops::Trace::set_threshold(3);
 
 my $i;
 for ( 1 .. 10 ) {
 	$i++;
 }
 
-Runops::Hook::disable();
+Runops::Trace::disable();
 
 is( $i, 10, "loop ran correctly" );
 
-ok( scalar(keys %{ Runops::Hook::counters() }), "counted something now" );
+ok( scalar(keys %{ Runops::Trace::counters() }), "counted something now" );

Modified: Runops-Hook/trunk/t/07perl_Hook.t
==============================================================================
--- Runops-Hook/trunk/t/07perl_Hook.t	(original)
+++ Runops-Hook/trunk/t/07perl_Hook.t	Sat May 10 08:52:20 2008
@@ -3,14 +3,14 @@
 use strict;
 use warnings;
 
-use Runops::Hook;
+use Runops::Trace;
 use Test::More 'no_plan';
 
 use Scalar::Util qw(refaddr);
 
 my ( $called, @ops, @refgen_args, @aassign_args );
 
-Runops::Hook::set_hook(sub {
+Runops::Trace::set_hook(sub {
 	my ( $hook, $op, $arity, @args ) = @_;
 
 	$called++;
@@ -30,7 +30,7 @@
 sub foo { sub { $i } };
 sub bar { sub { $i } };
 
-Runops::Hook::enable();
+Runops::Trace::enable();
 
 ++$i;
 my $j = $i + 42;
@@ -43,7 +43,7 @@
 	$j = "" . $i;
 }
 
-Runops::Hook::disable();
+Runops::Trace::disable();
 
 ++$i;
 

Modified: Runops-Hook/trunk/t/08fact.t
==============================================================================
--- Runops-Hook/trunk/t/08fact.t	(original)
+++ Runops-Hook/trunk/t/08fact.t	Sat May 10 08:52:20 2008
@@ -4,7 +4,7 @@
 use warnings;
 
 use Test::More qw(no_plan);
-use Runops::Hook;
+use Runops::Trace;
 
 use B::Concise;
 
@@ -21,7 +21,7 @@
 	}
 }
 
-Runops::Hook::set_hook(sub {
+Runops::Trace::set_hook(sub {
 	my ( $self, $op, $arity, @args ) = @_;
 
 	#warn "op name: ", $op->name, "($$op) arity: ", $arity, " args: ", \@args;
@@ -29,10 +29,10 @@
 	#Dump($_) for @args;
 });
 
-Runops::Hook::enable();
+Runops::Trace::enable();
 
 my $f = fact(3);
 
-Runops::Hook::disable();
+Runops::Trace::disable();
 
 is( $f, 6 );


More information about the Jifty-commit mailing list