| 1 | use strict; | ||
| 2 | package WWW::Scraper::Response::ScraperDiscovery; | ||
| 3 | |||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | WWW::Scraper::Response::ScraperDiscovery - | ||
| 8 | |||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | =head1 AUTHOR | ||
| 15 | |||
| 16 | C<WWW::Scraper::Response::ScraperDiscovery> is written and maintained | ||
| 17 | by Glenn Wood, http://search.cpan.org/search?mode=author&query=GLENNWOOD. | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | use vars qw($VERSION @ISA $CHECKED); | ||
| 22 | @ISA = qw(WWW::Scraper::Response); | ||
| 23 | use WWW::Scraper::Response; | ||
| 24 | $VERSION = sprintf("%d.%02d", q$Revision: 1.0 $ =~ /(\d+)\.(\d+)/); | ||
| 25 | my $CHECKED = 0; | ||
| 26 | my $MODE = ''; sub SetMODE { $MODE = $_[0] } | ||
| 27 | my $Iterator = '0'; sub GetIterator { $Iterator } | ||
| 28 | |||
| 29 | sub asHtml { | ||
| 30 | my ($self) = shift; | ||
| 31 | |||
| 32 | if ( $MODE eq 'ScraperFrame' ) { | ||
| 33 | return $self->asHTML_ScraperFrame(@_); | ||
| 34 | } else { | ||
| 35 | return $self->asHTML_RequestFrame(@_); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | sub asHTML_ScraperFrame { | ||
| 40 | my ($self) = shift; | ||
| 41 | my $typeLeaf = $self->typeLeaf; | ||
| 42 | |||
| 43 | my $attrList = ''; | ||
| 44 | my %results = %{$self->GetFieldValues()}; | ||
| 45 | for ( qw(id onmouseover onmouseout onclick onMouseOver onMouseOut) ) { delete $results{$_}; } # We are usurping these attributes. | ||
| 46 | my $val; | ||
| 47 | for ( keys %{$self->GetFieldTitles()} ) { | ||
| 48 | next if $_ eq 'content'; | ||
| 49 | next if $_ eq 'content'; | ||
| 50 | $val = $self->$_; | ||
| 51 | next unless $val; | ||
| 52 | $val = $$val; | ||
| 53 | # Let's escape quotes or apostrophes the cheapest way possible. | ||
| 54 | if ( $val !~ m{"} ) { | ||
| 55 | $val = "\"$val\""; | ||
| 56 | } elsif ( $val !~ m{'} ) { | ||
| 57 | $val = "\'$val\'" unless $val =~ m{'}; | ||
| 58 | } else { | ||
| 59 | $val =~ s{'}{%27}g; | ||
| 60 | $val = "'$val'"; | ||
| 61 | } | ||
| 62 | $attrList .= " $_=$val" if $val && $val ne '' | ||
| 63 | } | ||
| 64 | |||
| 65 | $attrList .= ' style=""' unless $attrList =~ m{style=}; # Make sure each element has a style, for Javascript. | ||
| 66 | $typeLeaf = 'DIV' if $typeLeaf eq 'BR'; | ||
| 67 | my ($content) = ($typeLeaf =~ m{^TD|BR|A$} ? ${$self->content}:''); | ||
| 68 | map { $content .= $_->asHtml } @{$self->SubHitList} if $self->SubHitList; | ||
| 69 | |||
| 70 | $Iterator += 1; | ||
| 71 | my $mouseEvents = ($typeLeaf =~ m{BODY})?'':" onmouseover='hilite(event)' onmouseout='lolite(event)'"; | ||
| 72 | return <<EOT; | ||
| 73 | <$typeLeaf$attrList ID='$Iterator'$mouseEvents'>$content</$typeLeaf> | ||
| 74 | EOT | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | sub asHtml_RequestFrame { | ||
| 79 | my ($self) = shift; | ||
| 80 | my $typeLeaf = $self->typeLeaf; | ||
| 81 | |||
| 82 | my $attrList = ''; | ||
| 83 | my %results = %{$self->GetFieldValues()}; | ||
| 84 | my $val; | ||
| 85 | for ( keys %{$self->GetFieldTitles()} ) { | ||
| 86 | next if $_ eq 'caption'; | ||
| 87 | $val = $self->$_; | ||
| 88 | next unless defined $val; | ||
| 89 | $val = $$val; | ||
| 90 | # Let's escape quotes or apostrophes the cheapest way possible. | ||
| 91 | if ( $val !~ m{"} ) { | ||
| 92 | $val = "\"$val\""; | ||
| 93 | } elsif ( $val !~ m{'} ) { | ||
| 94 | $val = "\'$val\'" unless $val =~ m{'}; | ||
| 95 | } else { | ||
| 96 | $val =~ s{'}{%27}g; | ||
| 97 | $val = "'$val'"; | ||
| 98 | } | ||
| 99 | $attrList .= " $_=$val" if $val && $val ne '' | ||
| 100 | } | ||
| 101 | |||
| 102 | my $content = ''; my $checked = ''; my $theCheckBox = ' '; | ||
| 103 | my $name = ref($self->name)?${$self->name}:''; | ||
| 104 | if ( $typeLeaf eq 'INPUT' ) { | ||
| 105 | if ( $attrList =~ m{type="(radio|checkbox)"} ) { | ||
| 106 | $content = $self->caption; | ||
| 107 | } elsif ( $attrList =~ m{type="hidden"} ) { | ||
| 108 | #$attrList =~ s{type="hidden"}{type='text' cols='10' readonly}i; | ||
| 109 | #$attrList =~ s{value=\S*}{value=' (hidden field)'}i unless | ||
| 110 | # $attrList =~ s{value='[^']*'}{value=' (hidden field)'}i || | ||
| 111 | # $attrList =~ s{value="[^"]*"}{value=" (hidden field)"}i; | ||
| 112 | $content = ' (hidden field)'; | ||
| 113 | } elsif ( $attrList =~ m{type=("text"|"")} ) { | ||
| 114 | unless ( $WWW::Scraper::Response::ScraperDiscovery::CHECKED ) { | ||
| 115 | $WWW::Scraper::Response::ScraperDiscovery::CHECKED = $self; | ||
| 116 | $checked = ' checked'; | ||
| 117 | } | ||
| 118 | $theCheckBox = "<input name='scraperDiscoveryQueryField' value='$name' type='radio'$checked>"; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | else { | ||
| 122 | map { $content .= $_->asHtml } @{$self->SubHitList} if $self->SubHitList; | ||
| 123 | } | ||
| 124 | |||
| 125 | return <<EOT; | ||
| 126 | <tr> | ||
| 127 | <td align='left'><input name='scraperDiscoveryNameOf_$name' value='$name' type='text' cols='15'></td> | ||
| 128 | <td width='10px'>$theCheckBox</td> | ||
| 129 | <td><$typeLeaf$attrList>$content</$typeLeaf></td> | ||
| 130 | </tr> | ||
| 131 | EOT | ||
| 132 | } | ||
| 133 | |||
| 134 | sub GenerateScraperRequest {} # Many Opcodes will have no impact on the scraperRequest. | ||
| 135 | 1; | ||
| 136 |