NAME
Test::Weaken::ExtraBits -- various extras for Test::Weaken
SYNOPSIS
use Test::Weaken::ExtraBits;
DESCRIPTION
This is a few helper functions for use with Test::Weaken.
EXPORTS
Nothing is exported by default, but the functions can be requested individually in the usual Exporter style (see Exporter).
use Test::Weaken::ExtraBits qw(ignore_Class_Singleton);
FUNCTIONS
Contents
$io = Test::Weaken::ExtraBits::contents_glob_IO ($ref)-
If
$refis a globref then return the contents of itsIOslot. This is the underlying Perl I/O of a file handle.Note that
Test::Weaken3.006 doesn't track IO objects by default so to detect leaks of them add totracked_typestoo,leaks (constructor => sub { ... }, contents => \&Test::Weaken::ExtraBits::contents_glob_IO, tracked_types => ['IO']);This is good for detecting an open file leaked through a Perl-level dup (see "open" in perlfunc) even after its original
$fhhandle is destroyed and freed.open my $dupfh, '<', $fh; # $dupfh holds and uses *$fh{IO}
Ignores
$bool = Test::Weaken::ExtraBits::ignore_global_functions ($ref)-
Return true if
$refis a coderef to a global function likesub foo {}A global function is identified by the
$refhaving a name and the current function under that name equal to this$ref. Plain functions created assub foo {}etc work, but redefinitions or function-creating modules likeMemoizeorconstantgenerally don't.The name in a coderef is essentially just a string from its original creation. Things like
Memoizeetc often end up with anonymous functions.constantonly ends up with a name in the symtab optimization case.See Sub::Name to add a name to a coderef, though you probably wouldn't want that merely to make
ignore_global_functions()work. (Though a name can helpcaller()and stack backtraces too.) $bool = ignore_functions ($ref, $funcname, $funcname, ...)-
Return true if
$refis a coderef to any of the given named functions. This is designed for use when making an ignore handler,sub my_ignore_callback { my ($ref) = @_; return (ignore_functions ($ref, 'Foo::Bar::somefunc', 'Quux::anotherfunc') || ...); }Each
$funcnameargument should be a fully-qualified string likeFoo::Bar::somefunc. Any functions which doesn't exist are skipped, so it doesn't matter if a particular package is loaded yet, etc.If you've got coderefs to functions you want to ignore then there's no need for
ignore_functions(), just test$ref==$mycoderefetc. $bool = Test::Weaken::ExtraBits::ignore_Class_Singleton ($ref)-
Return true if
$refis the singleton instance object of a class usingClass::Singleton. IfClass::Singletonis not loaded or not used by the$refobject then return false.Generally
Class::Singletonobjects are permanent, existing for the duration of the program. This ignore helps skip them.The current implementation requires
Class::Singletonversion 1.04 for itshas_instance()method. $bool = Test::Weaken::ExtraBits::ignore_DBI_globals ($ref)-
Return true if
$refis one of the variousDBImodule global objects.This is slightly dependent on the DBI implementation but currently means any
DBI::drdriver object. A driver object is created permanently for each driver loaded.DBI::dbhandles (created and destroyed in the usual way) refer to their respective driver object.A bug in Perl through to at least 5.10.1 related to lvalue
substr()means certain scratchpad temporaries holding "ImplementorClass" strings in DBI end up still alive afterDBI::dbandDBI::stobjects have finished with them, looking like leaks, but not. They aren't recognised byignore_DBI_globalscurrently. A workaround is to do a dummyDBI::dbhandle creation to flush out the old scratchpad.
SEE ALSO
Test::Weaken, Test::Weaken::Gtk2
HOME PAGE
http://user42.tuxfamily.org/test-variousbits/index.html
COPYRIGHT
Copyright 2008, 2009, 2010, 2011, 2012, 2015, 2017 Kevin Ryde
Test-VariousBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Test-VariousBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Test-VariousBits. If not, see http://www.gnu.org/licenses/.