line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::MySQL5::URL; |
2
|
7
|
|
|
7
|
|
25
|
use Mojo::Base 'Mojo::URL'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
28
|
|
3
|
|
|
|
|
|
|
|
4
|
8
|
50
|
|
8
|
1
|
34
|
sub new { shift->SUPER::new->parse(@_ ? @_ : 'mysql://') } |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub parse { |
7
|
8
|
|
|
8
|
1
|
64
|
my ($self, $url) = @_; |
8
|
8
|
|
|
|
|
17
|
$self->SUPER::parse($url); |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
100
|
|
|
780
|
$self->database($self->path->parts->[0] // ''); |
11
|
|
|
|
|
|
|
|
12
|
8
|
100
|
100
|
|
|
483
|
if (($self->userinfo // '') =~ /^([^:]+)(?::([^:]+))?$/) { |
13
|
3
|
|
|
|
|
23
|
$self->username($1); |
14
|
3
|
100
|
|
|
|
44
|
$self->password($2) if defined $2; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
|
|
50
|
my $hash = $self->query->to_hash; |
18
|
8
|
50
|
|
|
|
360
|
$self->{options} = { } unless exists $self->{options}; |
19
|
8
|
|
|
|
|
16
|
@{$self->options}{keys %$hash} = values %$hash; |
|
8
|
|
|
|
|
12
|
|
20
|
|
|
|
|
|
|
|
21
|
8
|
|
|
|
|
32
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub database { |
25
|
15
|
|
|
15
|
1
|
568
|
my $self = shift; |
26
|
15
|
100
|
50
|
|
|
43
|
return $self->{database} // '' unless @_; |
27
|
8
|
|
50
|
|
|
14
|
my $database = shift // ''; |
28
|
8
|
|
|
|
|
13
|
$self->{database} = $database; |
29
|
8
|
|
|
|
|
14
|
return $self->path($database); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub options { |
33
|
40
|
|
|
40
|
1
|
32
|
my $self = shift; |
34
|
40
|
50
|
|
|
|
121
|
return $self->{options} unless @_; |
35
|
0
|
|
|
|
|
0
|
$self->{options} = @_; |
36
|
0
|
|
|
|
|
0
|
return $self->query(@_); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub password { |
40
|
18
|
|
|
18
|
1
|
15
|
my $self = shift; |
41
|
18
|
100
|
100
|
|
|
84
|
return $self->{password} // '' unless @_; |
42
|
2
|
|
50
|
|
|
8
|
$self->{password} = shift // ''; |
43
|
2
|
50
|
|
|
|
3
|
return $self->userinfo($self->username . $self->password ? ':' . $self->password : ''); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub username { |
47
|
15
|
|
|
15
|
1
|
14
|
my $self = shift; |
48
|
15
|
100
|
100
|
|
|
65
|
return $self->{username} // '' unless @_; |
49
|
3
|
|
50
|
|
|
9
|
$self->{username} = shift // ''; |
50
|
3
|
100
|
|
|
|
6
|
return $self->userinfo($self->username . $self->password ? ':' . $self->password : ''); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub dsn { |
54
|
7
|
|
|
7
|
1
|
115
|
my $self = shift; |
55
|
7
|
|
|
|
|
11
|
my $dsn = 'dbi:mysql:dbname=' . $self->database; |
56
|
7
|
100
|
|
|
|
13
|
$dsn .= ';host=' . $self->host if $self->host; |
57
|
7
|
100
|
|
|
|
34
|
$dsn .= ';port=' . $self->port if $self->port; |
58
|
7
|
|
|
|
|
39
|
return $dsn; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding utf8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Mojo::MySQL5::URL - Connection URL |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Mojo::MySQL5::URL; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Parse |
74
|
|
|
|
|
|
|
my $url = Mojo::MySQL5::URL->new('mysql://sri:foo@server:3306/test?foo=bar'); |
75
|
|
|
|
|
|
|
say $url->username; |
76
|
|
|
|
|
|
|
say $url->password; |
77
|
|
|
|
|
|
|
say $url->host; |
78
|
|
|
|
|
|
|
say $url->port; |
79
|
|
|
|
|
|
|
say $url->database; |
80
|
|
|
|
|
|
|
say $url->options; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Build |
83
|
|
|
|
|
|
|
my $url = Mojo::MySQL5::URL->new; |
84
|
|
|
|
|
|
|
$url->scheme('mysql'); |
85
|
|
|
|
|
|
|
$url->userinfo('sri:foobar'); |
86
|
|
|
|
|
|
|
$url->host('server'); |
87
|
|
|
|
|
|
|
$url->port(3306); |
88
|
|
|
|
|
|
|
$url->database('test'); |
89
|
|
|
|
|
|
|
$url->options(foo => 'bar'); |
90
|
|
|
|
|
|
|
say "$url"; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L implements MySQL Connection string URL for using in L. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L inherits all attributes from L and implements the following new ones. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 database |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $db = $url->database; |
103
|
|
|
|
|
|
|
$url = $url->database('test'); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Database name. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 options |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $options = $url->options; |
110
|
|
|
|
|
|
|
$url = $url->options->{PrintError} = 1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Database options. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 password |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $password = $url->password; |
117
|
|
|
|
|
|
|
$url = $url->password('s3cret'); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Password part of URL. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 username |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $username = $url->username; |
124
|
|
|
|
|
|
|
$url = $url->username('batman'); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Username part of URL. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 METHODS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L inherits all methods from L and implements the |
131
|
|
|
|
|
|
|
following new ones. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 dsn |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $url = Mojo::MySQL5::URL->new('mysql://server:3000/test'); |
136
|
|
|
|
|
|
|
# dbi:mysql:dbname=test;host=server;port=3000 |
137
|
|
|
|
|
|
|
say $url->dsn; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Convert URL to L Data Source Name. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 parse |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$url->parse('mysql://server:3000/test'); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Parse URL string. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 new |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my $url = Mojo::MySQL5::URL->new; |
150
|
|
|
|
|
|
|
$url->parse('mysql://server:3000/test'); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $url = Mojo::MySQL5::URL->new('mysql://server:3000/test'); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L, L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |