| 1 | package Test::FIT::Cell; | ||
| 2 | $VERSION = '0.10'; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | sub new { | ||
| 6 | my ($class, $array, $index1, $index2) = @_; | ||
| 7 | $index2 = $index1 + 1 unless defined $index2; | ||
| 8 | my $self = bless [], $class; | ||
| 9 | $self->format_ref(\ $array->[$index1]); | ||
| 10 | $self->text_ref(\ $array->[$index2]); | ||
| 11 | return $self; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub format { | ||
| 15 | my $self = shift; | ||
| 16 | return ${$self->[0]} unless @_; | ||
| 17 | ${$self->[0]} = shift; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub format_ref { | ||
| 21 | my $self = shift; | ||
| 22 | return $self->[0] unless @_; | ||
| 23 | $self->[0] = shift; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub text { | ||
| 27 | my $self = shift; | ||
| 28 | return ${$self->[1]} unless @_; | ||
| 29 | ${$self->[1]} = shift; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub text_ref { | ||
| 33 | my $self = shift; | ||
| 34 | return $self->[1] unless @_; | ||
| 35 | $self->[1] = shift; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub method { | ||
| 39 | my $self = shift; | ||
| 40 | my $method = $self->text; | ||
| 41 | $method = $1 if $method =~ /(\w+)/; | ||
| 42 | return $method; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub class { | ||
| 46 | my $self = shift; | ||
| 47 | my $class = $self->text; | ||
| 48 | $class = $1 if $class =~ /([\w.:-]+)/; | ||
| 49 | return $class; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub clean_value { | ||
| 53 | my $self = shift; | ||
| 54 | my $value = $self->text; | ||
| 55 | if ($value =~ m!<pre>(.*)</pre>!is) { | ||
| 56 | $value = $1; | ||
| 57 | $value =~ s!<br>!\n!ig; | ||
| 58 | } | ||
| 59 | $value =~ s/^\s*(.*?)\s*$/$1/; | ||
| 60 | $value =~ s!<.*?>!!sg; | ||
| 61 | $value =~ s/\</</ig; | ||
| 62 | $value =~ s/\>/>/ig; | ||
| 63 | return $value; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub mark_passed { | ||
| 67 | my $self = shift; | ||
| 68 | my $format_ref = $self->format_ref; | ||
| 69 | $$format_ref =~ s/bgcolor=[^\s>]*//; | ||
| 70 | # $$format_ref =~ s/>/ bgcolor="#cfffcf">/; | ||
| 71 | $$format_ref =~ s/>/ bgcolor="#80ff80">/; | ||
| 72 | return unless @_; | ||
| 73 | $self->text(shift); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub mark_failed { | ||
| 77 | my $self = shift; | ||
| 78 | my $format_ref = $self->format_ref; | ||
| 79 | $$format_ref =~ s/bgcolor=[^\s>]*//; | ||
| 80 | # $$format_ref =~ s/>/ bgcolor="#ffcfcf">/; | ||
| 81 | $$format_ref =~ s/>/ bgcolor="#ff8080">/; | ||
| 82 | return unless @_; | ||
| 83 | $self->text(shift); | ||
| 84 | } | ||
| 85 | |||
| 86 | sub mark_error { | ||
| 87 | my $self = shift; | ||
| 88 | my $format_ref = $self->format_ref; | ||
| 89 | $$format_ref =~ s/bgcolor=[^\s>]*//; | ||
| 90 | # $$format_ref =~ s/>/ bgcolor="#ffffcf">/; | ||
| 91 | $$format_ref =~ s/>/ bgcolor="#ffff80">/; # XXX for laptop | ||
| 92 | return unless @_; | ||
| 93 | $self->text(shift); | ||
| 94 | } | ||
| 95 | |||
| 96 | 1; | ||
| 97 | |||
| 98 | __END__ |