in reply to Re: Cheaper - Debug,Log,Errors via Slicing&dicing
in thread Cheaper - Debug,Log,Errors via Slicing&dicing

right, I wasn't sure unslice() is working as expected..
I agree that this syntax is better :
no slice 'SomeModule';
Does this mean I have to implement module called 'slice' and then implement the unimport method. Is that what you meant ? I haven't done 'no'-module !

>>Further more, your slice isn't constant.
That's right, that was my idea. When I don't want to do debugging it is defined as constant, so it is inlined and pruned.
But when I need to debug it is a full blown sub. i.e. if I have the following code :
use Slicer; use constant slice => 0;
The constant will override the Slicer.pm definition, so no code will be executed.At least this is my understanding how it works and it seems to work.

In short to be inlined it has to be constant/sub-constant. To be able to override a constant I need a sub with prototype (), so that I can use the same name.
And finally to be able to call such sub() with many parameters I have to call it like this &mysub($p1,$p2)
Is my reasoning correct or there is a hole in it ;)

Replies are listed 'Best First'.
Re^3: Cheaper - Debug,Log,Errors via Slicing&dicing
by ikegami (Patriarch) on Jul 27, 2007 at 14:10 UTC

    Does this mean I have to implement module called 'slice' and then implement the unimport method. Is that what you meant ? I haven't done 'no'-module !

    I meant no Slicer 'SomeModule';, so you would create an unimport function instead of of unslice.

    The constant will override the Slicer.pm definition

    It will do that even if slice has no prototype. I notice you get a warning when you override, and two if there's a prototype mismatch, so may I suggest

    use if $ENV{SLICE}, 'Slicer'; use if !$ENV{SLICE}, 'constant', slice => 0;

    or better yet, move that logic into Slicer:

    package Slicer; use base Exporter; our @EXPORT = qw( slice ); sub _slice { my @caller = caller; print $caller[0]; print ":: sliced :" , @_; return 1; } if ($ENV{SLICE}) { *slice = \&_slice; } else { require constant; import constant slice => 0; } 1;

    Update: Nevermind, still doesn't work for slice(...). You really should use two functions instead of requiring people to use &.

    package Slicer; use base Exporter; our @EXPORT = qw( slice sliced ); use constant slice => $ENV{SLICE}; sub sliced { return unless slice; my @caller = caller; print $caller[0]; print ":: sliced :" , @_; } 1;
    >set SLICE= >perl -wle"use Slicer; print('!') if slice; >perl -wle"use Slicer; sliced('!'); >set SLICE=1 >perl -wle"use Slicer; print('!') if slice; ! >perl -wle"use Slicer; sliced('!'); main:: sliced :!