Test::Base::Filter(3)
π NAME π
Test::Base::Filter β Default Filter Class for Test::Base, aka the stock filter bestie for your data-driven tests. This is the Test::Base::Filter(3) page from the User Contributed Perl Documentation, and weβre gonna get you comfy with it π
β¨
β¨ SYNOPSIS β¨
okay so hereβs the setup vibe, bestie:
package MyTestSuite;
use Test::Base -Base;
... reusable testing code ...
package MyTestSuite::Filter;
use Test::Base::Filter -Base;
sub my_filter1 {
...
}
π¦ DESCRIPTION π¦
Filters are literally the key to writing effective data driven tests with Test::Base. Test::Base::Filter is a class containing a large default set of generic filters. You can easily subclass it to add/override functionality β main character energy, no cap π«Ά
πΈ FILTERS πΈ
This is a list of the default stock filters (in alphabetic order), and yes weβre going through all of them π
π append
type: list => list β Append a string to each element of a list.
--- numbers lines chomp append=-#\n join
one
two
three
π array
type: list => scalar β Turn a list of values into an anonymous array reference.
π§ base64_decode
type: scalar => scalar β Decode base64 data. Useful for binary tests.
π§ base64_encode
type: scalar => scalar β Encode base64 data. Useful for binary tests.
π chomp
type: list => list β Remove the final newline from each string value in a list.
π chop
type: list => list β Remove the final char from each string value in a list.
π dumper
type: scalar => list β Take a data structure (presumably from another filter like eval) and use Data::Dumper to dump it in a canonical fashion.
β¨ escape
type: scalar => scalar β Unescape all backslash escaped chars.
π₯ eval
type: scalar => list β Run Perlβs eval command against the data and use the returned value as the data.
π₯ eval_all
type: scalar => list β Run Perlβs eval command against the data and return a list of 4 values:
1) The return value
2) The error in $@
3) Captured STDOUT
4) Captured STDERR
π eval_stderr
type: scalar => scalar β Run Perlβs eval command against the data and return the captured STDERR.
π eval_stdout
type: scalar => scalar β Run Perlβs eval command against the data and return the captured STDOUT.
π exec_perl_stdout
type: list => scalar β Input Perl code is written to a temp file and run. STDOUT is captured and returned.
π¦ flatten
type: scalar => list β Takes a hash or array ref and flattens it to a list.
π get_url
type: scalar => scalar β The text is chomped and considered to be a url. Then LWP::Simple::get is used to fetch the contents of the url.
π«Ά hash
type: list => scalar β Turn a list of key/value pairs into an anonymous hash reference.
π head[=number]
type: list => list β Takes a list and returns a number of the elements from the front of it. The default number is one.
πΆ join
type: list => scalar β Join a list of strings into a scalar.
π« Join
Join the list of strings inside a list of array refs and return the strings in place of the array refs.
π§΅ lines
type: scalar => list β Break the data into an anonymous array of lines. Each line (except possibly the last one if the chomp filter came first) will have a newline at the end.
πΈ norm
type: scalar => scalar β Normalize the data. Change non-Unix line endings to Unix line endings.
π prepend=string
type: list => list β Prepend a string onto each of a list of strings.
π read_file
type: scalar => scalar β Read the file named by the current content and return the fileβs content.
πͺ regexp[=xism]
type: scalar => scalar β The regexp filter will turn your data section into a regular expression object. You can pass in extra flags after an equals sign.
If the text contains more than one line and no flags are specified, then the xism flags are assumed.
π reverse
type: list => list β Reverse the elements of a list.
π Reverse
type: list => list β Reverse the list of strings inside a list of array refs.
π° slice=x[,y]
type: list => list β Returns the element number x through element number y of a list.
β sort
type: list => list β Sorts the elements of a list in character sort order.
β Sort
type: list => list β Sort the list of strings inside a list of array refs.
βοΈ split[=string|pattern]
type: scalar => list β Split a string into a list. Takes an optional string or regexp as a parameter. Defaults to s+. Same as Perl split.
βοΈ Split[=string|pattern]
type: list => list β Split each of a list of strings and turn them into array refs.
π‘οΈ strict
type: scalar => scalar β Prepend the string:
use strict;
use warnings;
to the blockβs text.
πΎ tail[=number]
type: list => list β Return a number of elements from the end of a list. The default number is one.
π§Ό trim
type: list => list β Remove extra blank lines from the beginning and end of the data. This allows you to visually separate your test data with blank lines.
π unchomp
type: list => list β Add a newline to each string value in a list.
π write_file[=filename]
type: scalar => scalar β Write the content of the section to the named file. Return the filename.
π§ yaml
type: scalar => list β Apply the YAML::Load function to the data block and use the resultant structure. Requires YAML.pm.
π AUTHOR π
Ingy dΓΆt Net <ingy@cpan.org> β iconic author behavior, periodt π
π COPYRIGHT π
Copyright 2005-2018. Ingy dΓΆt Net. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>.
okay bestie, thatβs the whole Test::Base::Filter(3) manual page β perl v5.42.0, dated 2018-04-20. The footer says Test::Base::Filter(3) one more time, and we are obsessed πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Base 0.89-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms