Test::Vars(3)

πŸ“¦
version 0.017 Β· 2 versions
, in alpine 3.24

🌸 NAME 🌸

Test::Vars(3) β€” yep, that’s the manual page name, from the User Contributed Perl Documentation crew β€” and it Detects unused variables in perl modules. πŸ’…

πŸ’– VERSION πŸ’–

This document describes Test::Vars version 0.017. πŸŽ€

✨ SYNOPSIS ✨

okay so here’s the whole vibe at a glance, bestie:

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' ];

πŸ¦‹ DESCRIPTION πŸ¦‹

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 your source code tidy. ✨ It’s giving β€œclean up your room, but make it Perl.” 🧹

πŸ”₯ INTERFACE πŸ”₯

🫢 Exported 🫢

all_vars_ok(%args)

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:

"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. 🫣

vars_ok($lib, %args)

Tests $lib with %args.

See all_vars_ok. 🎯

πŸ§ͺ <test_vars($lib, $result_handler, %args)> πŸ§ͺ

This subroutine tests variables, but instead of outputting TAP, calls the $result_handler subroutine reference provided with the results of the test. πŸ“ž

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. 🧾

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. πŸ‘€

🧠 MECHANISM 🧠

Test::Vars is similar to a part of Test::Perl::Critic, but the mechanism is different. No cap. πŸ”

While Perl::Critic, the backend of Test::Perl::Critic, scans the source code as text, this module scans the compiled opcodes (or AST: abstract syntax tree) using the B module. See also B and its submodules. πŸ‘‘

βš™οΈ CONFIGURATION βš™οΈ

TEST_VERBOSE = 1 | 2 shows the way this module works. πŸͺ„

⚠️ CAVEATS ⚠️

Over time there have been reported a number of cases where Test-Vars fails to report unused variables. You can review most of these cases by going to our issue tracker on GitHub and selecting issues with the Bug label: πŸ›

https://github.com/houseabsolute/p5-Test-Vars/issues?q=is%3Aopen+is%3Aissue+label%3ABug

πŸ“¦ DEPENDENCIES πŸ“¦

Perl 5.10.0 or later. πŸ’ͺ

πŸ’€ BUGS πŸ’€

Please report new issues at our issue tracker on GitHub: https://github.com/houseabsolute/p5-Test-Vars/issues. We no longer use rt.cpan.org for bug reports. 🚫

πŸ‘€ SEE ALSO πŸ‘€

  • Perl::Critic
  • warnings::unused
  • B
  • Test::Builder::Module

πŸ‘‘ AUTHOR πŸ‘‘

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. πŸ’–


And that’s the tea, bestie: this page came from perl v5.42.2, dated 2024-09-18, and it’s Test::Vars(3) β€” slay. πŸ’…βœ¨

πŸ“¦ where this page comes from