blob: 2559f7a3ced6f8f47038956949a6475e4f592de0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/env perl
=head1 NAME
geocode - commandline tool to test geocoders
=head1 SYNOPSIS
$ bin/geocode --geocoder=Bing --cobrand=bromley "Glebe Rd"
# ... if your conf/general.yml supplies GEOCODER:
$ bin/geocode --cobrand=bromley "Glebe Rd"
# ... if you want to use config that you have in conf/general.bing.yml
$ bin/geocode --override-config=general.bing --cobrand=bromley "Glebe Rd"
## ... output from geocoder
=cut
use strict;
use warnings;
require 5.8.0;
BEGIN {
use File::Basename qw(dirname);
use File::Spec;
my $d = dirname(File::Spec->rel2abs($0));
require "$d/../setenv.pl";
}
use Data::Dumper;
use Pod::Usage;
use feature 'say';
use Getopt::Long;
my %options = ( help => sub { pod2usage(0) } );
GetOptions \%options,
'geocoder=s',
'help|h',
'cobrand=s',
'override-config=s';
my $s = join ' ', @ARGV
or pod2usage(0);
pod2usage(0) unless $options{cobrand};
local $ENV{FMS_OVERRIDE_CONFIG} = $options{'override-config'} if $options{'override-config'};
eval 'use FixMyStreet';
eval 'use FixMyStreet::App';
eval 'use FixMyStreet::Cobrand';
eval 'use FixMyStreet::Geocode';
mySociety::Locale::gettext_domain( 'FixMyStreet' );
my $geocoder_type = $options{geocoder} || do {
my $GEOCODER = FixMyStreet->config('GEOCODER');
ref $GEOCODER ? $GEOCODER->{type} : $GEOCODER;
} or pod2usage(0);
my $geocoder_name = "FixMyStreet::Geocode::${geocoder_type}";
my $code_ref = $geocoder_name->can('string')
or die "$geocoder_name is not a valid geocoder?";
my @allowed_cobrands = FixMyStreet::Cobrand->get_allowed_cobrands();
my $cobrand_name = FixMyStreet::Cobrand->get_class_for_moniker($options{cobrand});
my $cobrand = $cobrand_name->new();
say "USING COBRAND $cobrand_name";
if ($cobrand->moniker ne lc($options{cobrand})) {
say "!!! asked for $options{cobrand}";
say "!!! Check ALLOWED_COBRANDS setting in conf/general.yml (or supplied --override-config file)";
say Dumper(\@allowed_cobrands);
}
my $c = FixMyStreet::App->new();
$c->stash->{cobrand} = $cobrand;
say Dumper( $code_ref->( $s, $c ) );
|