9 @ISA = qw( HTML::Parser );
11 use vars qw($VERSION $BRANCH);
12 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
13 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
14 $main::build += $VERSION;
15 $main::branch += $BRANCH;
22 my $self = SUPER::new $pkg;
24 $self->{state} = 'pre';
25 $self->{sort} = undef;
27 $self->{call} = uc shift;
33 my ($self, $tag, $attr, $attrseq, $origtext) = @_;
35 print "$self->{state} $tag";
37 my $dd = new Data::Dumper([$attr], [qw(attr)]);
41 print " ", $dd->Dumpxs;
45 if ($self->{state} eq 'pre' && $tag eq 'table') {
47 } elsif ($self->{state} eq 't1' && $tag eq 'table') {
49 } elsif ($self->{state} eq 't2' && $tag =~ /^h/) {
53 } elsif ($self->{state} eq 'addr') {
55 $self->{addr} .= ", " if length $self->{addr} > $self->{laddr};
56 $self->{laddr} = length $self->{addr};
57 } elsif ($tag eq 'p') {
58 push @{$self->{list}}, $self->{addr} ? "$self->{call}|addr|$self->{addr}" : "$self->{call}|addr|unknown";
59 $self->state('semail');
61 } elsif ($self->{state} eq 'email') {
63 my $email = $attr->{href};
64 if ($email && $email =~ /mailto/i) {
65 $email =~ s/mailto://i;
66 push @{$self->{list}}, "$self->{call}|email|$email";
68 } elsif ($tag eq 'br' || $tag eq 'p') {
71 } elsif ($self->{state} eq 'post' && $tag eq 'form') {
72 if (exists $self->{pos} && length $self->{pos}) {
73 push @{$self->{list}}, "$self->{call}|location|$self->{pos}";
81 my ($self, $text) = @_;
82 $text =~ s/^[\s\r\n]+//g;
83 $text =~ s/[\s\r\n]+$//g;
84 print "$self->{state} text $text\n" if $self->{debug};
86 if ($self->{state} eq 'addr') {
87 $text =~ s/\ //gi;
88 $self->{addr} .= $text;
89 } elsif ($self->{state} eq 'semail' && $text =~ /Email/i ) {
90 $self->state('email');
91 } elsif ($self->{state} eq 'post') {
92 if ($text =~ /Latitude/i) {
94 $self->{pos} = "" unless $self->{pos};
95 } elsif ($text =~ /Longitude/i) {
97 $self->{pos} = "" unless $self->{pos};
98 } elsif ($text =~ /Grid/i) {
100 $self->{pos} = "" unless $self->{pos};
102 } elsif ($self->{state} eq 'lat') {
103 my ($n, $l) = $text =~ /(\b[\d\.]+\b)\s+([NSns])/;
104 $n = -$n if $l eq 'S' || $l eq 's';
105 $self->{pos} = slat($n);
106 $self->state('post');
107 } elsif ($self->{state} eq 'long') {
108 my ($n, $l) = $text =~ /(\b[\d\.]+\b)\s+([EWew])/;
109 $n = -$n if $l eq 'W' || $l eq 'w';
110 $self->{pos} .= "|" . slong($n);
111 $self->state('post');
112 } elsif ($self->{state} eq 'grid') {
113 my ($qra) = $text =~ /(\b\w\w\d\d\w\w\b)/;
114 $self->{pos} .= "|" . uc $qra;
115 push @{$self->{list}}, "$self->{call}|location|$self->{pos}";
116 $self->state('last');
117 } elsif (($self->{state} eq 'pre' || $self->{state} =~ /^t/) && $text =~ /not\s+found/) {
118 push @{$self->{list}}, "$self->{call}|addr|unknown";
119 $self->state('last');
120 } elsif ($self->{state} eq 'email' && $text =~ /unknown/i) {
121 $self->state('post');
129 $self->{state} = shift if @_;
130 return $self->{state};
135 my ($self, $tag, $origtext) = @_;
136 print "$self->{state} /$tag\n" if $self->{debug};
141 my ($self, $val) = @_;
142 $self->{debug} = $val;
148 return @{$self->{list}};