in reply to Re^2: Cheaper - Debug,Log,Errors via Slicing&dicing
in thread Cheaper - Debug,Log,Errors via Slicing&dicing
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 :!
|
|---|