File Coverage

inc/Test/Base.pm
Criterion Covered Total %
statement 270 384 70.3
branch 79 202 39.1
condition 22 83 26.5
subroutine 48 63 76.1
pod 20 29 68.9
total 439 761 57.6


line stmt bran cond sub pod time code
1             package Test::Base;
2             our $VERSION = '0.89';
3              
4 46     46   514181 use Spiffy -Base;
  46         183  
  46         331  
5 46     46   358 use Spiffy ':XXX';
  46     46   76  
  46     46   1127  
  46         168  
  46         60  
  46         2313  
  46         207  
  46         65  
  46         171  
6              
7             my $HAS_PROVIDER;
8             BEGIN {
9 46     46   2767 $HAS_PROVIDER = eval "require Test::Builder::Provider; 1";
10              
11 46 50       267 if ($HAS_PROVIDER) {
12 0         0 Test::Builder::Provider->import('provides');
13             }
14             else {
15 46     46   2674 *provides = sub { 1 };
  46         87  
16             }
17             }
18              
19              
20             my @test_more_exports;
21             BEGIN {
22 46     46   1730 @test_more_exports = qw(
23             ok isnt like unlike is_deeply cmp_ok
24             skip todo_skip pass fail
25             eq_array eq_hash eq_set
26             plan can_ok isa_ok diag
27             use_ok
28             $TODO
29             );
30             }
31              
32 46     46   31962 use Test::More import => \@test_more_exports;
  46         5076991  
  46         482  
33 46     46   16408 use Carp;
  46         96  
  46         28321  
34              
35             our @EXPORT = (@test_more_exports, qw(
36             is no_diff
37              
38             blocks next_block first_block
39             delimiters spec_file spec_string
40             filters filters_delay filter_arguments
41             run run_compare run_is run_is_deeply run_like run_unlike
42             skip_all_unless_require is_deep run_is_deep
43             WWW XXX YYY ZZZ
44             tie_output no_diag_on_only
45              
46             find_my_self default_object
47              
48             croak carp cluck confess
49             ));
50              
51             field '_spec_file';
52             field '_spec_string';
53             field _filters => [qw(norm trim)];
54             field _filters_map => {};
55             field spec =>
56             -init => '$self->_spec_init';
57             field block_list =>
58             -init => '$self->_block_list_init';
59             field _next_list => [];
60             field block_delim =>
61             -init => '$self->block_delim_default';
62             field data_delim =>
63             -init => '$self->data_delim_default';
64             field _filters_delay => 0;
65             field _no_diag_on_only => 0;
66              
67             field block_delim_default => '===';
68             field data_delim_default => '---';
69              
70             my $default_class;
71             my $default_object;
72             my $reserved_section_names = {};
73              
74 238     238 1 407 sub default_object {
75 238   66     3545 $default_object ||= $default_class->new;
76 238         496 return $default_object;
77             }
78              
79             my $import_called = 0;
80             sub import() {
81 92     92   1464 $import_called = 1;
82 92 100       722 my $class = (grep /^-base$/i, @_)
83             ? scalar(caller)
84             : $_[0];
85 92 100       376 if (not defined $default_class) {
86 46         91 $default_class = $class;
87             }
88             # else {
89             # croak "Can't use $class after using $default_class"
90             # unless $default_class->isa($class);
91             # }
92              
93 92 100       476 unless (grep /^-base$/i, @_) {
94 46         94 my @args;
95 46         253 for (my $ii = 1; $ii <= $#_; ++$ii) {
96 78 50       241 if ($_[$ii] eq '-package') {
97 0         0 ++$ii;
98             } else {
99 78         283 push @args, $_[$ii];
100             }
101             }
102 46 100       501 Test::More->import(import => \@test_more_exports, @args)
103             if @args;
104             }
105              
106 92         51498 _strict_warnings();
107 92         2239 goto &Spiffy::import;
108             }
109              
110             # Wrap Test::Builder::plan
111             my $plan_code = \&Test::Builder::plan;
112             my $Have_Plan = 0;
113             {
114 46     46   373 no warnings 'redefine';
  46         101  
  46         316922  
115             *Test::Builder::plan = sub {
116 46     46   442337 $Have_Plan = 1;
117 46         259 goto &$plan_code;
118             };
119             }
120              
121             my $DIED = 0;
122             $SIG{__DIE__} = sub { $DIED = 1; die @_ };
123              
124 33     33 0 43 sub block_class { $self->find_class('Block') }
  33         75  
125 187     187 0 216 sub filter_class { $self->find_class('Filter') }
  187         340  
126              
127 220     220 0 243 sub find_class {
128 220         272 my $suffix = shift;
129 220         373 my $class = ref($self) . "::$suffix";
130 220 100       709 return $class if $class->can('new');
131 33         50 $class = __PACKAGE__ . "::$suffix";
132 33 50       188 return $class if $class->can('new');
133 0         0 eval "require $class";
134 0 0       0 return $class if $class->can('new');
135 0         0 die "Can't find a class for $suffix";
136             }
137              
138 49     49 0 100 sub check_late {
139 49 50       208 if ($self->{block_list}) {
140 0         0 my $caller = (caller(1))[3];
141 0         0 $caller =~ s/.*:://;
142 0         0 croak "Too late to call $caller()"
143             }
144             }
145              
146             sub find_my_self() {
147 245 100   245 0 242489 my $self = ref($_[0]) eq $default_class
148             ? splice(@_, 0, 1)
149             : default_object();
150 245         1641 return $self, @_;
151             }
152              
153             sub blocks() {
154 3     3 1 35 (my ($self), @_) = find_my_self(@_);
155              
156 3 50       13 croak "Invalid arguments passed to 'blocks'"
157             if @_ > 1;
158 3 50 33     17 croak sprintf("'%s' is invalid argument to blocks()", shift(@_))
159             if @_ && $_[0] !~ /^[a-zA-Z]\w*$/;
160              
161 3         65 my $blocks = $self->block_list;
162              
163 3   50     18 my $section_name = shift || '';
164             my @blocks = $section_name
165 3 50       15 ? (grep { exists $_->{$section_name} } @$blocks)
  0         0  
166             : (@$blocks);
167              
168 3 50       8 return scalar(@blocks) unless wantarray;
169              
170 3 50       41 return (@blocks) if $self->_filters_delay;
171              
172 3         8 for my $block (@blocks) {
173 9 50       77 $block->run_filters
174             unless $block->is_filtered;
175             }
176              
177 3         15 return (@blocks);
178             }
179              
180             sub next_block() {
181 0     0 1 0 (my ($self), @_) = find_my_self(@_);
182 0         0 my $list = $self->_next_list;
183 0 0       0 if (@$list == 0) {
184 0         0 $list = [@{$self->block_list}, undef];
  0         0  
185 0         0 $self->_next_list($list);
186             }
187 0         0 my $block = shift @$list;
188 0 0 0     0 if (defined $block and not $block->is_filtered) {
189 0         0 $block->run_filters;
190             }
191 0         0 return $block;
192             }
193              
194             sub first_block() {
195 0     0 1 0 (my ($self), @_) = find_my_self(@_);
196 0         0 $self->_next_list([]);
197 0         0 $self->next_block;
198             }
199              
200             sub filters_delay() {
201 0     0 1 0 (my ($self), @_) = find_my_self(@_);
202 0 0       0 $self->_filters_delay(defined $_[0] ? shift : 1);
203             }
204              
205             sub no_diag_on_only() {
206 0     0 0 0 (my ($self), @_) = find_my_self(@_);
207 0 0       0 $self->_no_diag_on_only(defined $_[0] ? shift : 1);
208             }
209              
210             sub delimiters() {
211 46     46 1 378 (my ($self), @_) = find_my_self(@_);
212 46         435 $self->check_late;
213 46         163 my ($block_delimiter, $data_delimiter) = @_;
214 46   33     146 $block_delimiter ||= $self->block_delim_default;
215 46   33     141 $data_delimiter ||= $self->data_delim_default;
216 46         1615 $self->block_delim($block_delimiter);
217 46         893 $self->data_delim($data_delimiter);
218 46         144 return $self;
219             }
220              
221             sub spec_file() {
222 3     3 1 665975 (my ($self), @_) = find_my_self(@_);
223 3         19 $self->check_late;
224 3         72 $self->_spec_file(shift);
225 3         7 return $self;
226             }
227              
228             sub spec_string() {
229 0     0 1 0 (my ($self), @_) = find_my_self(@_);
230 0         0 $self->check_late;
231 0         0 $self->_spec_string(shift);
232 0         0 return $self;
233             }
234              
235             sub filters() {
236 6     6 1 499735 (my ($self), @_) = find_my_self(@_);
237 6 50       29 if (ref($_[0]) eq 'HASH') {
238 6         144 $self->_filters_map(shift);
239             }
240             else {
241 0         0 my $filters = $self->_filters;
242 0         0 push @$filters, @_;
243             }
244 6         26 return $self;
245             }
246              
247             sub filter_arguments() {
248 0     0 1 0 $Test::Base::Filter::arguments;
249             }
250              
251 0     0 0 0 sub have_text_diff {
252 0 0 0     0 eval { require Text::Diff; 1 } &&
  0         0  
  0         0  
253             $Text::Diff::VERSION >= 0.35 &&
254             $Algorithm::Diff::VERSION >= 1.15;
255             }
256              
257             provides 'is';
258             sub is($$;$) {
259 166     166 1 4396868 (my ($self), @_) = find_my_self(@_);
260 166         513 my ($actual, $expected, $name) = @_;
261 166 50       655 local $Test::Builder::Level = $Test::Builder::Level + 1 unless $HAS_PROVIDER;
262 166 50 33     914 if ($ENV{TEST_SHOW_NO_DIFFS} or
      33        
      0        
      0        
      0        
263             not defined $actual or
264             not defined $expected or
265             $actual eq $expected or
266             not($self->have_text_diff) or
267             $expected !~ /\n./s
268             ) {
269 166         615 Test::More::is($actual, $expected, $name);
270             }
271             else {
272 0 0       0 $name = '' unless defined $name;
273 0         0 ok $actual eq $expected, $name;
274 0         0 diag Text::Diff::diff(\$expected, \$actual);
275             }
276             }
277              
278             sub run(&;$) {
279 2     2 1 235547 (my ($self), @_) = find_my_self(@_);
280 2         5 my $callback = shift;
281 2         6 for my $block (@{$self->block_list}) {
  2         47  
282 12 50       9680 $block->run_filters unless $block->is_filtered;
283 12         14 &{$callback}($block);
  12         33  
284             }
285             }
286              
287             my $name_error = "Can't determine section names";
288 3     3   5 sub _section_names {
289 3 50       44 return unless defined $self->spec;
290 3 50       17 return @_ if @_ == 2;
291 0 0       0 my $block = $self->first_block
292             or croak $name_error;
293             my @names = grep {
294 0         0 $_ !~ /^(ONLY|LAST|SKIP)$/;
295 0 0       0 } @{$block->{_section_order}[0] || []};
  0         0  
296 0 0       0 croak "$name_error. Need two sections in first block"
297             unless @names == 2;
298 0         0 return @names;
299             }
300              
301 3     3   7 sub _assert_plan {
302 3 50       10 plan('no_plan') unless $Have_Plan;
303             }
304              
305 46     46   1628960 sub END {
306 46 0 33     1780 run_compare() unless $Have_Plan or $DIED or not $import_called;
      33        
307             }
308              
309             sub run_compare() {
310 0     0 1 0 (my ($self), @_) = find_my_self(@_);
311 0 0       0 return unless defined $self->spec;
312 0         0 $self->_assert_plan;
313 0         0 my ($x, $y) = $self->_section_names(@_);
314 0         0 local $Test::Builder::Level = $Test::Builder::Level + 1;
315 0         0 for my $block (@{$self->block_list}) {
  0         0  
316 0 0 0     0 next unless exists($block->{$x}) and exists($block->{$y});
317 0 0       0 $block->run_filters unless $block->is_filtered;
318 0 0       0 if (ref $block->$x) {
    0          
319 0 0       0 is_deeply($block->$x, $block->$y,
320             $block->name ? $block->name : ());
321             }
322             elsif (ref $block->$y eq 'Regexp') {
323 0 0       0 my $regexp = ref $y ? $y : $block->$y;
324 0 0       0 like($block->$x, $regexp, $block->name ? $block->name : ());
325             }
326             else {
327 0 0       0 is($block->$x, $block->$y, $block->name ? $block->name : ());
328             }
329             }
330             }
331              
332             sub run_is() {
333 1     1 1 7 (my ($self), @_) = find_my_self(@_);
334 1         26 $self->_assert_plan;
335 1         6 my ($x, $y) = $self->_section_names(@_);
336 1         4 local $Test::Builder::Level = $Test::Builder::Level + 1;
337 1         2 for my $block (@{$self->block_list}) {
  1         25  
338 5 100 66     2698 next unless exists($block->{$x}) and exists($block->{$y});
339 4 50       73 $block->run_filters unless $block->is_filtered;
340 4 50       10 is($block->$x, $block->$y,
341             $block->name ? $block->name : ()
342             );
343             }
344             }
345              
346             sub run_is_deeply() {
347 2     2 1 13 (my ($self), @_) = find_my_self(@_);
348 2         12 $self->_assert_plan;
349 2         23 my ($x, $y) = $self->_section_names(@_);
350 2         8 for my $block (@{$self->block_list}) {
  2         48  
351 7 50 33     4910 next unless exists($block->{$x}) and exists($block->{$y});
352 7 50       126 $block->run_filters unless $block->is_filtered;
353 7 50       16 is_deeply($block->$x, $block->$y,
354             $block->name ? $block->name : ()
355             );
356             }
357             }
358              
359             sub run_like() {
360 0     0 1 0 (my ($self), @_) = find_my_self(@_);
361 0         0 $self->_assert_plan;
362 0         0 my ($x, $y) = $self->_section_names(@_);
363 0         0 for my $block (@{$self->block_list}) {
  0         0  
364 0 0 0     0 next unless exists($block->{$x}) and defined($y);
365 0 0       0 $block->run_filters unless $block->is_filtered;
366 0 0       0 my $regexp = ref $y ? $y : $block->$y;
367 0 0       0 like($block->$x, $regexp,
368             $block->name ? $block->name : ()
369             );
370             }
371             }
372              
373             sub run_unlike() {
374 0     0 1 0 (my ($self), @_) = find_my_self(@_);
375 0         0 $self->_assert_plan;
376 0         0 my ($x, $y) = $self->_section_names(@_);
377 0         0 for my $block (@{$self->block_list}) {
  0         0  
378 0 0 0     0 next unless exists($block->{$x}) and defined($y);
379 0 0       0 $block->run_filters unless $block->is_filtered;
380 0 0       0 my $regexp = ref $y ? $y : $block->$y;
381 0 0       0 unlike($block->$x, $regexp,
382             $block->name ? $block->name : ()
383             );
384             }
385             }
386              
387             sub skip_all_unless_require() {
388 3     3 0 547437 (my ($self), @_) = find_my_self(@_);
389 3         10 my $module = shift;
390 3 100       145 eval "require $module; 1"
391             or Test::More::plan(
392             skip_all => "$module failed to load"
393             );
394             }
395              
396             sub is_deep() {
397 0     0 1 0 (my ($self), @_) = find_my_self(@_);
398 0         0 require Test::Deep;
399 0         0 Test::Deep::cmp_deeply(@_);
400             }
401              
402             sub run_is_deep() {
403 0     0 0 0 (my ($self), @_) = find_my_self(@_);
404 0         0 $self->_assert_plan;
405 0         0 my ($x, $y) = $self->_section_names(@_);
406 0         0 for my $block (@{$self->block_list}) {
  0         0  
407 0 0 0     0 next unless exists($block->{$x}) and exists($block->{$y});
408 0 0       0 $block->run_filters unless $block->is_filtered;
409 0 0       0 is_deep($block->$x, $block->$y,
410             $block->name ? $block->name : ()
411             );
412             }
413             }
414              
415 8     8   28 sub _pre_eval {
416 8         28 my $spec = shift;
417 8 50       39 return unless defined $spec;
418 8 50       48 return $spec unless $spec =~
419             s/\A\s*<<<(.*?)>>>\s*$//sm;
420 0         0 my $eval_code = $1;
421 0         0 eval "package main; $eval_code";
422 0 0       0 croak $@ if $@;
423 0         0 return $spec;
424             }
425              
426 8     8   17 sub _block_list_init {
427 8         130 my $spec = $self->spec;
428 8 50       32 return [] unless defined $spec;
429 8         75 $spec = $self->_pre_eval($spec);
430 8         134 my $cd = $self->block_delim;
431 8         1009 my @hunks = ($spec =~ /^(\Q${cd}\E.*?(?=^\Q${cd}\E|\z))/msg);
432 8         63 my $blocks = $self->_choose_blocks(@hunks);
433 8         137 $self->block_list($blocks); # Need to set early for possible filter use
434 8         13 my $seq = 1;
435 8         22 for my $block (@$blocks) {
436 33         278 $block->blocks_object($self);
437 33         252 $block->seq_num($seq++);
438             }
439 8         41 return $blocks;
440             }
441              
442 8     8   17 sub _choose_blocks {
443 8         18 my $blocks = [];
444 8         25 for my $hunk (@_) {
445 33         130 my $block = $self->_make_block($hunk);
446 33 50       69 if (exists $block->{ONLY}) {
447 0 0       0 diag "I found ONLY: maybe you're debugging?"
448             unless $self->_no_diag_on_only;
449 0         0 return [$block];
450             }
451 33 50       67 next if exists $block->{SKIP};
452 33         53 push @$blocks, $block;
453 33 50       96 if (exists $block->{LAST}) {
454 0         0 return $blocks;
455             }
456             }
457 8         18 return $blocks;
458             }
459              
460 80     80   83 sub _check_reserved {
461 80         109 my $id = shift;
462             croak "'$id' is a reserved name. Use something else.\n"
463 80 50 33     300 if $reserved_section_names->{$id} or
464             $id =~ /^_/;
465             }
466              
467 33     33   43 sub _make_block {
468 33         59 my $hunk = shift;
469 33         518 my $cd = $self->block_delim;
470 33         338 my $dd = $self->data_delim;
471 33         98 my $block = $self->block_class->new;
472 33 50       636 $hunk =~ s/\A\Q${cd}\E[ \t]*(.*)\s+// or die;
473 33         109 my $name = $1;
474 33         1252 my @parts = split /^\Q${dd}\E +\(?(\w+)\)? *(.*)?\n/m, $hunk;
475 33         69 my $description = shift @parts;
476 33   50     144 $description ||= '';
477 33 50       79 unless ($description =~ /\S/) {
478 33         51 $description = $name;
479             }
480 33         246 $description =~ s/\s*\z//;
481 33         100 $block->set_value(description => $description);
482              
483 33         44 my $section_map = {};
484 33         38 my $section_order = [];
485 33         93 while (@parts) {
486 80         177 my ($type, $filters, $value) = splice(@parts, 0, 3);
487 80         235 $self->_check_reserved($type);
488 80 50       158 $value = '' unless defined $value;
489 80 50       114 $filters = '' unless defined $filters;
490 80 50       116 if ($filters =~ /:(\s|\z)/) {
491 0 0       0 croak "Extra lines not allowed in '$type' section"
492             if $value =~ /\S/;
493 0         0 ($filters, $value) = split /\s*:(?:\s+|\z)/, $filters, 2;
494 0 0       0 $value = '' unless defined $value;
495 0         0 $value =~ s/^\s*(.*?)\s*$/$1/;
496             }
497 80         198 $section_map->{$type} = {
498             filters => $filters,
499             };
500 80         111 push @$section_order, $type;
501 80         123 $block->set_value($type, $value);
502             }
503 33         98 $block->set_value(name => $name);
504 33         60 $block->set_value(_section_map => $section_map);
505 33         56 $block->set_value(_section_order => $section_order);
506 33         69 return $block;
507             }
508              
509 8     8   18 sub _spec_init {
510 8 50       177 return $self->_spec_string
511             if $self->_spec_string;
512 8         38 local $/;
513 8         16 my $spec;
514 8 100       124 if (my $spec_file = $self->_spec_file) {
515 3 50       214 open FILE, $spec_file or die $!;
516 3         150 $spec = ;
517 3         38 close FILE;
518             }
519             else {
520 5         44 require Scalar::Util;
521 5         31 my $handle = Scalar::Util::openhandle( \*main::DATA );
522 5 50       17 if ($handle) {
523 5         199 $spec = <$handle>;
524             }
525             }
526 8         79 return $spec;
527             }
528              
529             sub _strict_warnings() {
530 92     92   628 require Filter::Util::Call;
531 92         178 my $done = 0;
532             Filter::Util::Call::filter_add(
533             sub {
534 179 100   179   182600 return 0 if $done;
535 92         273 my ($data, $end) = ('', '');
536 92         1060 while (my $status = Filter::Util::Call::filter_read()) {
537 7028 50       10271 return $status if $status < 0;
538 7028 100       11639 if (/^__(?:END|DATA)__\r?$/) {
539 5         16 $end = $_;
540 5         15 last;
541             }
542 7023         8413 $data .= $_;
543 7023         16148 $_ = '';
544             }
545 92         837 $_ = "use strict;use warnings;$data$end";
546 92         2822 $done = 1;
547             }
548 92         792 );
549             }
550              
551             sub tie_output() {
552 0     0 1 0 my $handle = shift;
553 0 0       0 die "No buffer to tie" unless @_;
554 0         0 tie *$handle, 'Test::Base::Handle', $_[0];
555             }
556              
557 46     46 1 758 sub no_diff {
558 46         768 $ENV{TEST_SHOW_NO_DIFFS} = 1;
559             }
560              
561             package Test::Base::Handle;
562              
563             sub TIEHANDLE() {
564 0     0   0 my $class = shift;
565 0         0 bless \ $_[0], $class;
566             }
567              
568 0     0   0 sub PRINT {
569 0         0 $$self .= $_ for @_;
570             }
571              
572             #===============================================================================
573             # Test::Base::Block
574             #
575             # This is the default class for accessing a Test::Base block object.
576             #===============================================================================
577             package Test::Base::Block;
578             our @ISA = qw(Spiffy);
579              
580             our @EXPORT = qw(block_accessor);
581              
582 5     5   116 sub AUTOLOAD {
583 5         11 return;
584             }
585              
586             sub block_accessor() {
587 129     129   242 my $accessor = shift;
588 46     46   568 no strict 'refs';
  46         2170  
  46         11569  
589 129 50       780 return if defined &$accessor;
590             *$accessor = sub {
591 293     293   13963 my $self = shift;
592 293 50       506 if (@_) {
593 0         0 Carp::croak "Not allowed to set values for '$accessor'";
594             }
595 293 50       316 my @list = @{$self->{$accessor} || []};
  293         751  
596             return wantarray
597 293 100       1737 ? (@list)
598             : $list[0];
599 129         735 };
600             }
601              
602             block_accessor 'name';
603             block_accessor 'description';
604             Spiffy::field 'seq_num';
605             Spiffy::field 'is_filtered';
606             Spiffy::field 'blocks_object';
607             Spiffy::field 'original_values' => {};
608              
609 410     410   427 sub set_value {
610 46     46   340 no strict 'refs';
  46         78  
  46         14569  
611 410         447 my $accessor = shift;
612 410 100       905 block_accessor $accessor
613             unless defined &$accessor;
614 410         1241 $self->{$accessor} = [@_];
615             }
616              
617 32     32   45 sub run_filters {
618 32         60 my $map = $self->_section_map;
619 32         61 my $order = $self->_section_order;
620 32 50       313 Carp::croak "Attempt to filter a block twice"
621             if $self->is_filtered;
622 32         57 for my $type (@$order) {
623 78         155 my $filters = $map->{$type}{filters};
624 78         179 my @value = $self->$type;
625 78         977 $self->original_values->{$type} = $value[0];
626 78         167 for my $filter ($self->_get_filters($type, $filters)) {
627 198 50       405 $Test::Base::Filter::arguments =
628             $filter =~ s/=(.*)$// ? $1 : undef;
629 198         291 my $function = "main::$filter";
630 46     46   362 no strict 'refs';
  46         66  
  46         36402  
631 198 100       754 if (defined &$function) {
632 11 50 33     67 local $_ =
633             (@value == 1 and not defined($value[0])) ? undef :
634             join '', @value;
635 11         15 my $old = $_;
636 11         35 @value = &$function(@value);
637 11 50 33     1211 if (not(@value) or
      33        
      33        
638             @value == 1 and defined($value[0]) and $value[0] =~ /\A(\d+|)\z/
639             ) {
640 0 0 0     0 if ($value[0] && $_ eq $old) {
641 0         0 Test::Base::diag("Filters returning numbers are supposed to do munging \$_: your filter '$function' apparently doesn't.");
642             }
643 0         0 @value = ($_);
644             }
645             }
646             else {
647 187         1954 my $filter_object = $self->blocks_object->filter_class->new;
648 187 50       338 die "Can't find a function or method for '$filter' filter\n"
649             unless $filter_object->can($filter);
650 187         1818 $filter_object->current_block($self);
651 187         438 @value = $filter_object->$filter(@value);
652             }
653             # Set the value after each filter since other filters may be
654             # introspecting.
655 198         770 $self->set_value($type, @value);
656             }
657             }
658 32         372 $self->is_filtered(1);
659             }
660              
661 78     78   92 sub _get_filters {
662 78         89 my $type = shift;
663 78   50     254 my $string = shift || '';
664 78         407 $string =~ s/\s*(.*?)\s*/$1/;
665 78         111 my @filters = ();
666 78   100     784 my $map_filters = $self->blocks_object->_filters_map->{$type} || [];
667 78 100       186 $map_filters = [ $map_filters ] unless ref $map_filters;
668 78         103 my @append = ();
669 78         99 for (
670 78         697 @{$self->blocks_object->_filters},
671             @$map_filters,
672             split(/\s+/, $string),
673             ) {
674 198         234 my $filter = $_;
675 198 50       289 last unless length $filter;
676 198 50       425 if ($filter =~ s/^-//) {
    50          
677 0         0 @filters = grep { $_ ne $filter } @filters;
  0         0  
678             }
679             elsif ($filter =~ s/^\+//) {
680 0         0 push @append, $filter;
681             }
682             else {
683 198         389 push @filters, $filter;
684             }
685             }
686 78         225 return @filters, @append;
687             }
688              
689             {
690             %$reserved_section_names = map {
691             ($_, 1);
692             } keys(%Test::Base::Block::), qw( new DESTROY );
693             }
694              
695             1;