forked from garu/Data-Printer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PR garu#74 to void PPI dependency.
Pull request garu#74 'show variable name as __VAR__' had a dependency on the PPI module which made its inclusion in the master less atractive for the users not using the feature. By refactoring the part of the code that depended on PPI out in a separate module, only the users that would like to use the feature needs to install PPI. The code remaining in master (that does not depend on PPI) now implements a plugin hook in the write_label() sub in Data::Printer::Object. An option in the configuration file called 'caller_plugin' is used to register a caller plugin. If such a plugin is registered, write_label() will load the plugin and then call the plugin to do the generation of the label string. The refactored part of garu#74 that depends on PPI has been included in the module Data::Printer::Plugin::Caller::PPI (currently on Github).
- Loading branch information
1 parent
a1e214f
commit ec96ebe
Showing
3 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
BEGIN { | ||
use Data::Printer::Config; | ||
no warnings 'redefine'; | ||
*Data::Printer::Config::load_rc_file = sub { {} }; | ||
}; | ||
|
||
use Data::Printer colored => 0, | ||
use_prototypes => 0, | ||
caller_info => 1, | ||
caller_plugin => 'Foo'; | ||
|
||
if (!eval { require Capture::Tiny; 1; }) { | ||
plan skip_all => 'Capture::Tiny not found'; | ||
} | ||
else { | ||
plan tests => 1; | ||
} | ||
|
||
{ | ||
# Try to force require(..) for a caller plugin to fail.. | ||
|
||
# In the case the user by chance should have installed a module with | ||
# the same name as the caller plugin, make sure it will not be found | ||
# by erasing @INC : | ||
local @INC = ('./lib'); | ||
|
||
# NOTE: local $INC{'Data/Printer/Plugin/Caller/Foo.pm'} does not work | ||
# it just sets $INC{'Data/Printer/Plugin/Caller/Foo.pm'} to undef | ||
# but that is enough for require "Data/Printer/Plugin/Caller/Foo.pm" not | ||
# to fail, so we have to delete the key (and the value): | ||
my $save = delete $INC{'Data/Printer/Plugin/Caller/Foo.pm'}; | ||
my $var = 1; | ||
my ($stdout, $stderr) = Capture::Tiny::capture( | ||
sub { | ||
p \$var, output => *STDOUT; | ||
} | ||
); | ||
like $stderr, qr/Failed to load caller plugin/, 'missing plugin'; | ||
$INC{'Data/Printer/Plugin/Caller/Foo.pm'} = $save if defined $save; | ||
} |