Dancer-Plugin-Mango
view release on metacpan or search on metacpan
lib/Dancer/Plugin/Mango.pm view on Meta::CPAN
$dbh->default_db($settings->{db_name})
if defined $settings->{db_name};
if (defined $settings->{username} && defined $settings->{password}) {
push @{$settings->{db_credentials}}, [ $settings->{db_name}, $settings->{username}, $settings->{password}];
}
if (defined $settings->{db_credentials} and ref $settings->{db_credentials} eq 'ARRAY') {
$dbh->credentials($settings->{db_credentials});
}
if (defined $settings->{ioloop}) {
my ( $module, $function ) = split(/\-\>/, $settings->{ioloop});
$dbh->ioloop($module->$function);
}
if (defined $settings->{j}) {
$dbh->j($settings->{j})
};
if (defined $settings->{max_bson_size}) {
$dbh->max_bson_size($settings->{max_bson_size})
};
if (defined $settings->{max_connections}) {
$dbh->max_connections($settings->{max_connections})
}
if (defined $settings->{max_write_batch_size}) {
$dbh->max_write_batch_size($settings->{max_write_batch_size})
}
if ( defined $settings->{protocol}) {
my ( $module, $function ) = split(/\-\>/, $settings->{protocol});
$dbh->protocol($module->$function);
}
if ( defined $settings->{w}) {
$dbh->w($settings->{w})
}
if ( defined $settings->{wtimeout}) {
$dbh->wtimeout($settings->{wtimeout})
}
#$dbh->on( error => \&_mango_error() );
#$dbh->on( connection => \&_mango_connection() );
if (!$dbh) {
$logger->(error => "Database connection failed - " . $lasterror);
execute_hook('database_connection_failed', $settings);
return;
}
execute_hook('database_connected', $dbh);
return $dbh;
}
# Check the connection is alive
sub _check_connection {
my $dbh = shift;
return unless $dbh;
my $curs;
$lasterror = undef;
eval {
$curs = $dbh->db($settings->{db_name})->collection('prototype')->find_one();
};
if (!defined $lasterror) {
return 1;
}
return;
}
sub _mango_error {
my ( $mango, $err ) = @_;
$lasterror = $err;
return;
}
sub _mango_connection {
return;
}
sub _get_settings {
my $name = shift;
my $return_settings;
# If no name given, just return the default settings
if (!defined $name) {
$return_settings = { %$settings };
# Yeah, you can have ZERO settings in Mongo.
} else {
# If there are no named connections in the config, bail now:
return unless exists $settings->{connections};
# OK, find a matching config for this name:
if (my $named_settings = $settings->{connections}{$name}) {
# Take a (shallow) copy of the settings, so we don't change them
$return_settings = { %$named_settings };
} else {
# OK, didn't match anything
$logger->('error',
"Asked for a database handle named '$name' but no matching "
."connection details found in config"
);
}
}
# If the setting wasn't provided, default to 30 seconds; if a false value is
# provided, though, leave it alone. (Older versions just checked for
# truthiness, so a value of zero would still default to 30 seconds, which
# isn't ideal.)
if (!exists $return_settings->{connection_check_threshold}) {
$return_settings->{connection_check_threshold} = 30;
( run in 1.820 second using v1.01-cache-2.11-cpan-39bf76dae61 )