Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:54:15+00:00 2026-06-12T05:54:15+00:00

In the POD for Test::Base , there is an example on rolling my own

  • 0

In the POD for Test::Base, there is an example on rolling my own filters, which the documentation says is “self explanatory”. I am having trouble understanding it and I think it may be a problem in my filter writing. The code is reproduced below:

use Test::Base;

filters 'foo', 'bar=xyz';

sub foo {
    transform(shift);
}

sub Test::Base::Filter::bar {
    my $self = shift;       # The Test::Base::Filter object
    my $data = shift;
    my $args = $self->current_arguments;
    my $current_block_object = $self->block;
    # transform $data in a barish manner
    return $data;
}

The filters function sets the named subroutines as filters on the incoming data. The declared filters are ‘foo’ and ‘bar’, which has arguments.

My question is why the structure of foo and bar are so different. Why is foo in the current namespace while bar is declared in the Test::Base::Filter namespace? And why does foo alter its first argument, while bar must grab the data from the second argument?

Another example. In MyTest.pm:

package t::MyTest;
use Test::Base -Base;
#some stuff here

package t::MyTest::Filter;
use base 'Test::Base::Filter';

sub choose {
    print @_;
    return {foo => 'bar'} if($_[0] eq '1');
    return undef;
}
sub is_defined{ 
    print @_;
    defined $_[0];
}

And in test.t:

use t::MyTest;

filters {input => [qw(choose is_defined)] };
__END__
=== First
--- input
1
--- expected: 1
=== Second
--- input
0
--- expected: 0

If you place both of those in a “t” folder and run prove -v, this is the output:

t\01-test.t .. Use of uninitialized value $_[1] in print at t/MyTest.pm line 14,
 <DATA> line 1.

1
t::MyTest::Filter=HASH(0x2af1670)ok 1 - First
1..1
Failed 1/1 subtests

Test Summary Report
-------------------
t\01-test.t (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: Bad plan.  You planned 1 tests but ran 0.
Files=1, Tests=0,  1 wallclock secs ( 0.06 usr +  0.23 sys =  0.30 CPU)
Result: FAIL

Nevermind the warning (which I don’t completely understand the root of). Why is the first filter passed the input (like it’s supposed to be), but the second one is passed some Filter object? Shouldn’t the input of the second filter be the output of the first? If it isn’t, then I have to worry about filter ordering all over the place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:54:16+00:00Added an answer on June 12, 2026 at 5:54 am

    I figured this out. I’m pretty sure it’s a bug in the way filters work.
    The POD says:

    Each filter can take either a scalar or a list as input, and will return either a scalar or a list. Since filters are chained together, it is important to learn which filters expect which kind of input and return which kind of output.
    

    Perldoc tells me that undef is a valid scalar in Perl, but Test::Base::Filter ignores it. Normally the input to a Filter would be first the data, and then some other stuff. However, if a filter returns undef, then its return value is ignored and the next filter gets one less argument, instead of getting undef as its first argument. I’ll file this in RT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to write multilanguage documentation using POD? If no, what should
If there is a POD structure, with some member variables, for example like this:
I have a one-page OpenOffice document which is a POD template. Basically, I use
I was trying out some stuff allocating structs, which contain non-pod members, on the
There is a simple POD data type like struct Item { int value1; double
Possible Duplicates: Why is there a special new and delete for arrays? ( POD
There is this macro offsetof in C/C++ which allows you to get the address
I have some code which takes a packed POD structure/class and copies it into
Consider this POD: struct T { int i; char c; }; In which C++
I need to convert Pod to HTML. There are number of Pod::HTML and Pod::Simple::*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.