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