line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
WWW::StreetMap - Interface to http://www.streetmap.co.uk/ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use WWW::StreetMap; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Interface to http://www.streetmap.co.uk/ |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Please respect the terms and conditions of the excellent streetmap website: |
14
|
|
|
|
|
|
|
http://www.streetmap.co.uk/disclaimer.htm |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package WWW::StreetMap; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# pragmata |
25
|
1
|
|
|
1
|
|
59695
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
26
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Standard Perl Library and CPAN modules |
29
|
1
|
|
|
1
|
|
1212
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
29209
|
|
|
1
|
|
|
|
|
57
|
|
30
|
1
|
|
|
1
|
|
411
|
use Image::Magick; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use IO::All; |
32
|
|
|
|
|
|
|
use IO::All::LWP; |
33
|
|
|
|
|
|
|
use OpenOffice::OODoc; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$VERSION = '0.18'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 CLASS METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
new(url => $url) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
|
|
|
|
|
|
my($class, %options) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
die "No URL specified\n" unless $options{url}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $self = { |
52
|
|
|
|
|
|
|
url => $options{url}, |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
bless $self, $class; |
56
|
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 build_map_jpg |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
build_map_jpg |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Download the map from streetmap and join it into a single jpeg image. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub build_map_jpg { |
70
|
|
|
|
|
|
|
my($self, $filename) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return unless $filename; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# I guess could use WWW::Mechanize and its get_all_links instead of this.... |
75
|
|
|
|
|
|
|
my @lines = io($self->{url})->slurp; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my @image_urls = grep (/image.dll/, @lines); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
map { s! ^.*SRC="([^"]+)".*$ !$1!x } @image_urls; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my @filenames = (); |
83
|
|
|
|
|
|
|
my $image = Image::Magick->new; |
84
|
|
|
|
|
|
|
foreach my $url (@image_urls) { |
85
|
|
|
|
|
|
|
my ($fh, $filename) = tempfile(SUFFIX=>'gif'); |
86
|
|
|
|
|
|
|
chomp $url; |
87
|
|
|
|
|
|
|
io($url) > io($filename); |
88
|
|
|
|
|
|
|
$image->Read($filename); |
89
|
|
|
|
|
|
|
close $fh; # auto deletes |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $map = $image->Montage(geometry=>'200x200', tile => '3x3'); |
93
|
|
|
|
|
|
|
$map->Write($filename); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 create_oo_doc |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
create_oo_doc($filename, $map_filename) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Create an OpenOffice Writer document containg the map. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
If you do not specify a pre-existing map then $map_filename will default to |
103
|
|
|
|
|
|
|
$filename with the .jpg extension added. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub create_oo_doc { |
109
|
|
|
|
|
|
|
my($self, $filename, $map_filename) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return unless $filename; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
unless($map_filename) { |
114
|
|
|
|
|
|
|
$map_filename = "$filename.jpg"; |
115
|
|
|
|
|
|
|
$self->build_map_jpg($map_filename); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# create the File object |
119
|
|
|
|
|
|
|
my $oofile = ooFile($filename, create => 'text') or die "Something was wrong !\n"; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# get the current local time in OpenOffice.org-compliant format |
122
|
|
|
|
|
|
|
my $oodate = ooLocaltime; |
123
|
|
|
|
|
|
|
# get access to its metadata |
124
|
|
|
|
|
|
|
my $metadata = ooMeta(archive => $oofile); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# set the current time as the creation date |
127
|
|
|
|
|
|
|
$metadata->creation_date($oodate); |
128
|
|
|
|
|
|
|
# set the current time as modification date |
129
|
|
|
|
|
|
|
$metadata->date($oodate); |
130
|
|
|
|
|
|
|
# set the title, if provided |
131
|
|
|
|
|
|
|
$metadata->title("Map"); |
132
|
|
|
|
|
|
|
# saving (before here, the file didn't exist) |
133
|
|
|
|
|
|
|
$oofile->save; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $document = OpenOffice::OODoc::Document->new(file => $filename); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$document->createImageElement( |
139
|
|
|
|
|
|
|
"Map", |
140
|
|
|
|
|
|
|
import => $map_filename, |
141
|
|
|
|
|
|
|
size => "10cm, 10cm", |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# save the modified document |
145
|
|
|
|
|
|
|
$document->save; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 INSTALLATION |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This module uses Module::Build for its installation. To install this module type |
154
|
|
|
|
|
|
|
the following: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
perl Build.PL |
157
|
|
|
|
|
|
|
./Build |
158
|
|
|
|
|
|
|
./Build test |
159
|
|
|
|
|
|
|
./Build install |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
If you do not have Module::Build type: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
perl Makefile.PL |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
to fetch it. Or use CPAN or CPANPLUS and fetch it "manually". |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This module requires these other modules and libraries: |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Test::More |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Test::More is only required for testing purposes |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This module has these optional dependencies: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Test::Distribution |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This is just requried for testing purposes. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 TODO |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Construction of URL by user specifying Post Code, London Street etc. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 BUGS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
To report a bug or request an enhancement use CPAN's excellent Request Tracker, |
195
|
|
|
|
|
|
|
either via the web: |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
or via email: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
bug-www-streetmap@rt.cpan.org |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This source is part of a SourceForge project which always has the |
206
|
|
|
|
|
|
|
latest sources in svn. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
http://sourceforge.net/projects/sagar-r-shah/ |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 AUTHOR |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Sagar R. Shah |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 COPYRIGHT |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Copyright 2004-7, Sagar R. Shah, All rights reserved |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
219
|
|
|
|
|
|
|
the same terms as Perl itself. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|