Test::Vars - Detects unused variables in perl modules
This document describes Test::Vars version 0.013.
use Test::Vars; # Check all libs that are listed in the MANIFEST file all_vars_ok(); # Check an arbitrary file vars_ok('t/lib/MyLib.pm'); # Ignore some variables while checking vars_ok 't/lib/MyLib2.pm', ignore_vars => [ '$an_unused_var' ];
Test::Vars provides test functions to report unused variables either in an entire distribution or in some files of your choice in order to keep the source code tidy.
Tests libraries in your distribution with %args.
libraries are collected from the MANIFEST file.
If you want to ignore variables, for example $foo, you can tell it to the test routines:
$foo
ignore_vars => { '$foo' => 1 }
ignore_vars => [qw($foo)]
ignore_if => sub{ $_ eq '$foo' }
Note that $self will be ignored by default unless you pass explicitly { '$self' => 0 } to ignore_vars.
$self
{ '$self' => 0 }
ignore_vars
Tests $lib with %args.
See all_vars_ok.
all_vars_ok
This subroutine tests variables, but instead of outputting TAP, calls the $result_handler subroutine reference provided with the results of the test.
$result_handler
The $result_handler sub will be called once, with the following arguments:
$filename
The file that was checked for unused variables.
$exit_code
The value of $? from the child process that actually did the tests. This will be 0 if the tests passed.
$?
$results
This is an array reference which in turn contains zero or more array references. Each of those references contains two elements, a Test::Builder method, either diag or note, and a message.
diag
note
If the method is diag, the message contains an actual error. If the method is notes, the message contains extra information about the test, but is not indicative of an error.
notes
Test::Vars is similar to a part of Test::Perl::Critic,but the mechanism is different.
Test::Vars
Test::Perl::Critic
While Perl::Critic, the backend of Test::Perl::Critic, scans the source code as texts, this modules scans the compiled opcode (or AST: abstract syntax tree) using the B module. See also B and its submodules.
Perl::Critic
B
TEST_VERBOSE = 1 | 2 shows the way this module works.
TEST_VERBOSE = 1 | 2
https://rt.cpan.org/Ticket/Display.html?id=60018
https://rt.cpan.org/Ticket/Display.html?id=82411
Perl 5.10.0 or later.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
warnings::unused
Test::Builder::Module
Goro Fuji (gfx) <gfuji(at)cpan.org>
Copyright (c) 2010, Goro Fuji (gfx). All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic for details.
To install Test::Vars, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Vars
CPAN shell
perl -MCPAN -e shell install Test::Vars
For more information on module installation, please visit the detailed CPAN module installation guide.