URI-Shortener

 view release on metacpan or  search on metacpan

lib/URI/Shortener.pm  view on Meta::CPAN

    my ($self) = @_;
    my $dbname = $self->{dbname};
    return $self->{dbh}->{$dbname} if exists $self->{dbh}->{$dbname};

    my $host = $self->{dbhost} // $ENV{MYSQL_HOST} || 'localhost';
    my $port = $self->{dbport} // $ENV{MYSQL_TCP_PORT} || 3306;
    my $user = $self->{dbuser} // $ENV{DBI_USER};
    my $pass = $self->{dbpass} // $ENV{MYSQL_PWD};

    # Handle the mysql defaults file
    my $defaults_file = $self->{mysql_read_default_file} // "$ENV{HOME}/.my.cnf";
    my $defaults_group = $self->{mysql_read_default_group} // 'client';
    my $df = "";
    $df .= "mysql_read_default_file=$defaults_file;"   if -f $defaults_file;
    $df .= "mysql_read_default_group=$defaults_group;" if $defaults_group;

    my $dsn = "dbi:mysql:mysql_multi_statements=1;database=$dbname;".$df."host=$host;port=$port";

    my $db = DBI->connect($dsn, $user, $pass);
    $db->do($self->{mysql_schema}) or die "Could not ensure database consistency: " . $db->errstr;
    $self->{dbh}->{$dbname} = $db;
    return $db;
}

lib/URI/Shortener.pm  view on Meta::CPAN


=item C<dbhost,dbport,dbuser,dbpass>

Means to connect to remote databases, such as is the case with mysql/pg

dbhost defaults to localhost, and dbport defaults to the relevant default port.
Otherwise the relevant ENV vars are obeyed when no options are passed.

See _my_dbh() and _pg_dbh() for the particulars.

Also, mysql will obey the mysql_read_default_file/group parameters, and defaults to using ~/.my.cnf and the 'client' group.

=item C<prefix>

URI prefix of shortened output.  Trailing slashes will be stripped.  Example: https://big.hugs/go/

=item C<length>

Length of the minified path component. Defaulted to 12 when not a member of the natural numbers.

=item C<domain>



( run in 0.277 second using v1.01-cache-2.11-cpan-05444aca049 )