#!/usr/bin/perl -w
use strict;
use WWW::Search::Pagesjaunes;
use Getopt::Long;
use Pod::Usage;

my %opt;
GetOptions(
    \%opt,                    'activite|business|activity=s',
    'nom|name=s',             'prenom|firstname:s',
    'adresse|address:s',      'localite|ville|city|town=s',
    'departement|district=s', 'limit:i', 'english', 'quiet',
    'help|aide',              'man', 'separator|separateur=s',
    'version'
  )
  or pod2usage(2);

#
# $form->value('input_image', $x) o $x est:
# 
# CD_PDR_SUP_REG           => Rgion entire
# CD_PDR_SUP_DEP_REQ       => Dpartement entier
# CD_PDR_VOISIN_REQ        => Localits voisines
# CD_PDR_INSCRIPTIONS_REQ  => Sans nom ni adresse
# BT_INSCRIPTIONS_REQ_PROF => Afficher seulement les professionnels
# 
 
die "$WWW::Search::Pagesjaunes::VERSION\n" if $opt{version};

pod2usage(1) if $opt{help};
pod2usage( -verbose => 2 ) if $opt{man};
pod2usage("$0: No town or district given.") unless ($opt{localite} || $opt{departement});
pod2usage("$0: No business or name given.")
  unless ( $opt{activite} || $opt{nom} );

my $pj = WWW::Search::Pagesjaunes->new();

$pj->{lang}  = 'EN' if $opt{english};
$pj->{error} = 0    if $opt{quiet};

$pj->find(%opt);

do {
	local $\ = "\n";
	print join($opt{separator} || ' - ', $_->entry) foreach ( $pj->results );
} while $pj->has_more;

__END__

=head1 NAME

pagesjaunes - Lookup phones numbers from www.pagesjaunes.fr

=head1 SYNOPSIS

pagesjaunes [options ...]

 Options:
    -activite    -business  : Business type
    -nom         -name      : Name
    -prenom      -firstname : First name
    -localite    -town      : Town
    -departement -district  : Dept district or Region

    -separator : Character used to separate the fields (default ' - ')
    -limit     : Maximum number of results returned
    -english   : Use the pagesjaunes.fr english interface
    -quiet     : Turn off error messages display
    -help      : Brief help message
    -man       : Full documentation
    -version   : Display version number

You must provide the localite/town option, and either activite/business
or nom/name option. The prenom/firstname option is ignored if the
localite/town option is set.

=head1 OPTIONS

=over 8

=item B<-activite> or B<-business>

Activity or business type you're looking for. This is a mandatory switch
if you don't specify the B<-name> or B<-nom> switches.

=item B<-nom> or B<-name>

Name of the person or company you're looking for. Note that the search
is done with a fuzzy match.

=item B<-prenom> or B<-firstname>

First name of the person you're looking for. This option is ignored if
the B<-activite> or B<-business> are set.

=item B<-adresse> or B<-address>

Address of the person you're searching for.

=item B<-localite> or B<-town>

Name of the town.

=item B<-department> or B<-district>

Department district or Region you're searching in.

=item B<-limit>

Maximum number of entries returned. Default is 50. If you set it to 0 or
a negative number, it will return all the entries found.

=item B<-english>

Use the english interface of pagesjaunes.fr. This means that you can
enter business types in english (i.e. 'plumber' instead of 'plombier'),
and error messages will be displayed in english.

=item B<-quiet>

No error messages are printed when this switch is on

=item B<-help>

Print a brief help message and exits.

=item B<-man>

Prints the manual page and exits.

=item B<-version>

Prints the version of the script and exits.

=back

=head1 DESCRIPTION

This script provides name, phone number and addresses of French
telephone subscribers by using the http://www.pagesjaunes.fr directory
and the WWW::Search::Pagesjaunes module.

=head1 COPYRIGHT

Please read the Publisher information of L<http://www.pagesjaunes.fr>
available at the following URL:
L<http://www.pagesjaunes.fr/pj.cgi?html-=commun/avertissement.html&lang=en>

This script is Copyright (C) 2002, Briac Pilpr

This script is free software; you can redistribute it or modify it under
the same terms as Perl itself.

=head1 AUTHOR

Briac Pilpr <briac@cpan.org>

=cut

