FIT/Harness.pm untested

filter: Statementstmt 0.0% 0 / 90 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 149 CC 6 SCAR 23.2
CC
6
Cov
0%
fixtures_from_html
30.0
to_html
6.0
run_cgi
2.0
CRAP 10.2
1 package Test::FIT::Harness;
2 $VERSION = '0.10';
3 use strict;
4 use base 'Test::FIT::Fixture';
5 use Test::FIT;
6 use Test::FIT::Cell;
7  
8 use CGI ();
9 use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
10  
11 attribute('input_html');
12 attribute('parsed_html');
13 attribute('fixtures');
14  
15 sub run_cgi {
16 my $url = shift(@ARGV);
17 $url ||= CGI::referer()
18 or die "No FIT url detected\n";
19 my $fit = Test::FIT::Harness->new();
20 $fit->from_url($url);
21 print CGI::header(), $fit->to_html;
22 }
23  
24 sub from_url {
25 require LWP::Simple;
26 my ($self, $url) = @_;
27  
28 my $html = LWP::Simple::get($url) or die;
29 $self->input_html($html);
30 $self->parse_html;
31 $self->fixtures_from_html;
32 for my $fixture (@{$self->fixtures}) {
33 $fixture->process;
34 }
35 }
36  
37 sub parse_html {
38 my $self = shift;
39 my $html = $self->input_html;
40 my $parts = [];
41 @$parts = ($html =~ m#
42 (.*?)
43 ( <body\b.*?>
44 | <table\b.*?>
45 | <tr\b.*?>
46 | <td\b.*?>
47 | </td>
48 | </tr>
49 | </table>
50 | <a\b.*?>
51 )
52 #gsix);
53 push @$parts, $'; # XXX supposedly a slowdown.
54 $self->parsed_html($parts);
55 }
56  
57 sub fixtures_from_html {
58 my $self = shift;
59 my $parts = $self->parsed_html;
60 my $i = 0;
61 $self->fixtures([]);
62 while (1) {
63 $i++ while ($i < @$parts or last) and $parts->[$i] !~ /^<table\b/i;
64 $i++ while ($i < @$parts or last) and $parts->[$i] !~ /^<td\b/i;
65 my $fixture_cell = Test::FIT::Cell->new($parts, $i);
66 my $fixture_class = $fixture_cell->class;
67 eval qq{require $fixture_class};
68 if ($@) {
69 $fixture_cell->mark_error($@);
70 next;
71 }
72 my $fixture = $fixture_class->new;
73 $fixture->fixture_cell($fixture_cell);
74 my $matrix = [];
75 my $row;
76  
77 while ($i < @$parts and $parts->[$i] !~ m!^</table>!i) {
78 if ($parts->[$i] =~ /^<tr\b/) {
79 $row = [];
80 push @$matrix, $row;
81 $i++;
82 next;
83 }
84 elsif ($parts->[$i] =~ /^<td\b/) {
85 my $cell = Test::FIT::Cell->new($parts, $i);
86 push @$row, $cell;
87 $i += 2;
88 next;
89 }
90 else {
91 $i++;
92 next;
93 }
94 }
95 $fixture->matrix($matrix);
96 unless ($fixture->has_errors) {
97 my $fixtures = $self->fixtures;
98 push @$fixtures, $fixture;
99 $self->fixtures($fixtures);
100 }
101 }
102 }
103  
104 sub to_html {
105 require CGI;
106 my $self = shift;
107 join '', map {
108 if (/^<a\b.*?href=['"].*?cgi['"]/is) {
109 s/href=/hrefxxx=/i;
110 $_ = q{<a href="} . CGI::referer() . q{">&lt;&lt;&lt;</a>} . $_;
111 }
112 $_
113 } @{$self->parsed_html};
114 }
115  
116 1;
117  
118 __END__