FIT/Fixture.pm untested

filter: Statementstmt 0.0% 0 / 121 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 23 totaltotal 0.0% 0 / 206 CC 15 SCAR 23.8
CC
15
Cov
0%
process
42.0
matrix
20.0
cols
6.0
CRAP 10.8
1 package Test::FIT::Fixture;
2 $VERSION = '0.10';
3 use strict;
4 use Test::FIT;
5  
6 attribute 'has_errors';
7 attribute 'headers';
8 attribute 'fixture_cell';
9 attribute 'value';
10 attribute 'passed';
11 attribute 'failed';
12 attribute 'erred';
13 attribute 'text';
14 attribute 'x';
15 attribute 'y';
16 attribute 'z';
17  
18 sub XXX {
19 require YAML;
20 my $self = shift;
21 local $YAML::UseVersion = 0;
22 die YAML::Dump(@_);
23 }
24  
25 sub WWW {
26 require YAML;
27 my $self = shift;
28 warn("<pre>" . YAML::Dump(@_) . "</pre>");
29 }
30  
31 my $header_printed = 0;
32 $SIG{__WARN__} = sub {
33 print CGI::header() unless $header_printed++;
34 my $warning = join '', @_;
35 $warning =~ s/\n/<BR>\n/g;
36 print qq{<P><FONT COLOR="red">WARNING</FONT></P>\n$warning\n};
37 };
38  
39 sub new {
40 my ($class) = @_;
41 my $self = bless {}, $class;
42 $self->has_errors(0);
43 return $self;
44 }
45  
46 sub matrix {
47 my $self = shift;
48 return $self->{matrix} unless @_;
49 my $matrix = $self->{matrix} = shift;
50 $self->set_headers;
51 return if $self->has_errors;
52 for my $header (@{$self->headers}) {
53 my $method = $header->method;
54 unless ($self->can($method)) {
55 $header->mark_error;
56 $self->has_errors(1);
57 }
58 }
59 }
60  
61 sub rows {
62 my $self = shift;
63 my $matrix = $self->{matrix};
64 return scalar @$matrix;
65 }
66  
67 sub cols {
68 my $self = shift;
69 my $matrix = $self->{matrix};
70 return 0 unless defined $matrix->[0];
71 return scalar @{$matrix->[0]};
72 }
73  
74 sub process {
75 my $self = shift;
76 while ($self->cols and $self->rows) {
77 $self->has_errors(0);
78 my $slice = $self->next_slice;
79 for my $header (@{$self->headers}) {
80 my $method = $header->method;
81 my $cell = shift @$slice;
82 my $value = $cell->clean_value;
83 $self->value($value);
84 $self->passed(0);
85 $self->failed(0);
86 $self->erred(0);
87 $self->text('');
88 $self->$method($value);
89 my $text = $self->text;
90 my @text = length($text) ? ($text) : ();
91 $cell->mark_passed(@text) if $self->passed;
92 $cell->mark_failed(@text) if $self->failed;
93 $cell->mark_error(@text) if $self->erred;
94 last if $self->has_errors;
95 }
96 }
97 }
98  
99 sub pretty {
100 my ($self, $text) = @_;
101 $text =~ s/</\&lt;/g;
102 $text =~ s/>/\&gt;/g;
103 if ($text =~ /\n/) {
104 $text = "<pre>$text</pre>\n";
105 }
106 return $text;
107 }
108  
109 sub x_eq_str {$_[0]->eq_str($_[0]->x)}
110 sub x_is_like {$_[0]->is_like($_[0]->x)}
111  
112 sub eq_str {
113 my ($self, $got) = @_;
114 $self->ok($got eq $self->value);
115 }
116  
117 sub ne_str {
118 my ($self, $got) = @_;
119 $self->ok($got ne $self->value);
120 }
121  
122 sub is_like {
123 my ($self, $got) = @_;
124 my $pattern = $self->value;
125 $self->ok($got =~ m/$pattern/);
126 }
127  
128 sub is_unlike {
129 my ($self, $got) = @_;
130 my $pattern = $self->value;
131 $self->ok($got !~ m/$pattern/);
132 }
133  
134 sub eq_num {
135 my ($self, $got) = @_;
136 $self->ok($got == $self->value);
137 }
138  
139 sub ne_num {
140 my ($self, $got) = @_;
141 $self->ok($got != $self->value);
142 }
143  
144 sub ok {
145 my ($self, $ok) = @_;
146 $ok ? $self->pass : $self->fail;
147 }
148  
149 sub stop {
150 my $self = shift;
151 $self->has_errors(1);
152 }
153  
154 sub pass {
155 my $self = shift;
156 $self->passed(1);
157 $self->text($self->pretty(shift)) if @_;
158 }
159  
160 sub fail {
161 my $self = shift;
162 $self->failed(1);
163 $self->text($self->pretty(shift)) if @_;
164 }
165  
166 sub error {
167 my $self = shift;
168 $self->erred(1);
169 $self->text($self->pretty(shift)) if @_;
170 }
171  
172 sub set_headers {
173 my $self = shift;
174 my $class = ref $self;
175 die "$class needs to implement set_headers";
176 }
177  
178 sub next_slice {
179 my $self = shift;
180 my $class = ref $self;
181 die "$class needs to implement next_slice";
182 }
183  
184 1;
185  
186 __END__