File: dr.pm

package info (click to toggle)
libdbd-cassandra-perl 0.57-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: perl: 286; makefile: 2
file content (110 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package DBD::Cassandra::dr;
our $AUTHORITY = 'cpan:TVDW';
$DBD::Cassandra::dr::VERSION = '0.57';
# ABSTRACT: DBD::Cassandra driver handle

use 5.010;
use strict;
use warnings;

use Cassandra::Client 0.10;

# "*FIX ME* Explain what the imp_data_size is, so that implementors aren't
#  practicing cargo-cult programming" - DBI::DBD docs
$DBD::Cassandra::dr::imp_data_size = 0;

sub connect {
    my ($drh, $dr_dsn, $user, $auth, $attr)= @_;

    # Iterate through the DSN, write to $attr
    my $driver_prefix= 'cass_';
    for my $var (split /;/, $dr_dsn) {
        my ($attr_name, $attr_val)= split '=', $var, 2;
        return $drh->set_err($DBI::stderr, "Can't parse DSN part '$var'")
            unless defined $attr_val;

        $attr_name= "cass_$attr_name" unless $attr_name =~ /\A$driver_prefix/o;

        $attr->{$attr_name}= $attr_val;
    }

    my $keyspace= delete $attr->{cass_database} || delete $attr->{cass_db} || delete $attr->{cass_keyspace};
    my $host= delete $attr->{cass_host} || delete $attr->{cass_hostname} || delete $attr->{cass_hosts} || delete $attr->{cass_hostnames} || 'localhost';
    my $hosts= [ grep $_, split /,/, $host ];
    my $port= delete $attr->{cass_port} || 9042;
    my $global_consistency= delete $attr->{cass_consistency};
    my $compression= delete $attr->{cass_compression};
    my $cql_version= delete $attr->{cass_cql_version};
    my $read_timeout= delete $attr->{cass_read_timeout};
    my $write_timeout= delete $attr->{cass_write_timeout};
    my $connect_timeout= delete $attr->{cass_connect_timeout}; #XXX
    my $request_timeout= delete $attr->{cass_request_timeout};
    my $tls= delete $attr->{cass_tls};
    if ($read_timeout || $write_timeout) {
        if ($request_timeout) {
            warn 'Ignoring read_timeout and write_timeout settings, as request_timeout is passed';
        } else {
            $request_timeout= ($read_timeout || 6) + ($write_timeout || 6);
        }
    }

    my $client= Cassandra::Client->new(
        contact_points => $hosts,
        port => $port,
        username => $user,
        password => $auth,
        keyspace => $keyspace,
        compression => $compression,
        default_consistency => $global_consistency,
        cql_version => $cql_version,
        request_timeout => $request_timeout,
        anyevent => 0,
        tls => $tls,
    );
    my ($error)= $client->call_connect;
    return $drh->set_err($DBI::stderr, "Can't connect to $dr_dsn: $error") if $error;

    my ($outer, $dbh)= DBI::_new_dbh($drh, { Name => $dr_dsn });

    $dbh->STORE('Active', 1);
    $dbh->{cass_client}= $client;

    return $outer;
}

sub data_sources {
    my ($drh, $attr)= @_;
    my @array= (qw/dbi:Cassandra/);
    return @array;
}

sub disconnect_all {
    # TODO: not needed?
}

1;

__END__

=pod

=head1 NAME

DBD::Cassandra::dr - DBD::Cassandra driver handle

=head1 VERSION

version 0.57

=head1 AUTHOR

Tom van der Woerdt <tvdw@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Tom van der Woerdt.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut