use strict; my $pkg_top = 'InfoSys'; my $pkg_base = "${pkg_top}::FreeDB"; my $pkg = $pkg_base; my $pkg_connection = "${pkg_base}::Connection"; my $pkg_entry = "${pkg_base}::Entry"; push (@::bean_desc, { bean_opt => { package => $pkg, short_description => 'FreeDB connection factory', abstract => 'FreeDB connection factory', synopsis => &::read_synopsis( 'syn-http.pl', '.' ), description => < is the connection factory of the C<${pkg}> module hierarchy. This class creates connections using the protocols supported by FreeDB*. \=over \=item (*) Currently CDDBP and HTTP protocols are supported. \=back EOF todo => < [ ], constr_opt => [ ], meth_opt => [ { method_name => 'create_connection', parameter_description => 'OPT_HASH_REF', description => < object. C is a hash reference used to pass connection creation options. On error an exception C is thrown. \=over \=item SPEED-UP NOTE If protocol level C<1> is specified, the C method tries to use the highest available protocol level. To do so, it queries the FreeDB to find out exaclty which level is supported. On C connections this doesn't take that long. On C connections it does. To speed up C connections specify a higher C -say C<5>. \=back Options for C may include: \=over \=item B> Connect the created object just after instantiation. Defaults to C<1>. \=item B> The hostname of the client. Defaults to C<&Sys::Hostname::hostname()>. \=item B> Mandatory option to name the connecting client software. \=item B> The user name of the client. Defaults to C) )>. \=item B> Mandatory option with the client software version string. \=item B>* The FreeDB C to use. Defaults to C<~cddb/cddb.cgi>. \=item B> The FreeDB host. Defaults to C. \=item B> The port on the FreeDB host. Defaults to C<80> for C and to C<888> for C connection types. \=item B> The protocol to use. Either C or C. Defaults to C. \=item B> The FreeDB protocol level. Defaults to B<1>. \=item B>** The proxy host to use. \=item B>** The proxy password to use. \=item B>** The port on the proxy host. Defaults to 8080. \=item B>** The proxy user name to use. \=back \=over \=item (*) Only supported for the HTTP protocol. \=item (**) Proxy is only supported for the HTTP protocol. \=back EOF body => <<'EOF', my $self = shift; my $opt = defined($_[0]) ? shift : {}; # Check $opt ref($opt) eq 'HASH' || throw Error::Simple("ERROR: InfoSys::FreeDB::create_connection, first argument must be 'HASH' reference."); # Set default values for $opt $opt->{client_host} = &Sys::Hostname::hostname() if (! $opt->{client_host} ); $opt->{client_user} = scalar( getpwuid($>) ) if (! $opt->{client_user} ); $opt->{freedb_host} = 'freedb.freedb.org' if (! $opt->{freedb_host} ); # Set default value to protocol $opt->{protocol} = 'HTTP' if ( ! $opt->{protocol} ); # Select the correct connection class my $conn = undef; if ( $opt->{protocol} eq 'HTTP' ) { $opt->{freedb_port} = 80 if (! $opt->{freedb_port} ); require InfoSys::FreeDB::Connection::HTTP; $conn = InfoSys::FreeDB::Connection::HTTP->new($opt); } elsif ( $opt->{protocol} eq 'CDDBP' ){ $opt->{freedb_port} = 888 if (! $opt->{freedb_port} ); require InfoSys::FreeDB::Connection::CDDBP; $conn = InfoSys::FreeDB::Connection::CDDBP->new($opt); } else { throw Error::Simple("ERROR: InfoSys::FreeDB::create_connection, protocol '$opt->{protocol}' is not supported. Only 'HTTP' and 'CDDBP' are."); } # Connect if necessary $opt->{auto_connected} = 1 if ( !exists( $opt->{auto_connected} ) ); $opt->{auto_connected} && $conn->connect(); # Return the connection return($conn); EOF }, ], use_opt => [ { dependency_name => 'Sys::Hostname', }, ], } );