MySQL5/URL.pm

filter: Statementstmt 55.2% 21 / 38 Branchbran 20.8% 5 / 24 Conditioncond 18.7% 3 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 62.5% 5 / 8 Podpod 100% 7 / 7 totaltotal 40.5% 41 / 101 SCAR 48.7
CC
21
Cov
37%
password
30.0
username
30.0
dsn
12.0
CRAP 130.3
« MySQL5/Database.pm ↑ Summary MySQL5/Results.pm »
1 package Mojo::MySQL5::URL;
2 1 ▶use Mojo::Base 'Mojo::URL';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶sub new { shift->SUPER::new->parse(@_ ? @_ : 'mysql://') }
Subroutine new: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
5
6 sub parse {
7 1 ▶ my ($self, $url) = @_;
Subroutine parse: called CC=6 SCAR=20.8
Pod documented
8 1 $self->SUPER::parse($url);
9  
10 1 ▶ $self->database($self->path->parts->[0] // '');
Condition50%1/2
$self->path->parts->[0] // ""
l!l
01
MC/DC0%0/1
$self->path->parts->[0] // ""
$self->path->parts->[0]
Truth table50%1/2
A
A= $self->path->parts->[0]
Aresult
11
00
11  
12 1 ▶ if (($self->userinfo // '') =~ /^([^:]+)(?::([^:]+))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (($self->userinfo // "") =~ /^([^:]+)(?::([^:]+))?$/u) 0 1 1
Condition50%1/2
$self->userinfo // ""
l!l
01
MC/DC0%0/1
$self->userinfo // ""
$self->userinfo
Truth table50%1/2
A
A= $self->userinfo
Aresult
11
00
13 0 $self->username($1);
14 0 ▶ $self->password($2) if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 0 0 0
15 }
16  
17 1 my $hash = $self->query->to_hash;
18 1 ▶ $self->{options} = { } unless exists $self->{options};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"options"} 1 0 1
19 1 @{$self->options}{keys %$hash} = values %$hash;
20  
21 1 return $self;
22 }
23  
24 sub database {
25 1 ▶ my $self = shift;
Subroutine database: called CC=4 SCAR=15.6
Pod documented
26 1 ▶ return $self->{database} // '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
Condition0%0/2
$self->{"database"} // ""
l!l
00
MC/DC0%0/1
$self->{"database"} // ""
$self->{"database"}
Truth table0%0/2
A
A= $self->{"database"}
Aresult
11
00
27 1 ▶ my $database = shift // '';
Condition50%1/2
shift() // ""
l!l
10
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
28 1 $self->{database} = $database;
29 1 return $self->path($database);
30 }
31  
32 sub options {
33 2 ▶ my $self = shift;
Subroutine options: called CC=2 SCAR=9.2
Pod documented
34 2 ▶ return $self->{options} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 0 2
35 0 $self->{options} = @_;
36 0 return $self->query(@_);
37 }
38  
39 sub password {
40 0 ▶ my $self = shift;
Subroutine password: not called CC=5 SCAR=34.0
Pod documented
41 0 ▶ return $self->{password} // '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
Condition0%0/2
$self->{"password"} // ""
l!l
00
MC/DC0%0/1
$self->{"password"} // ""
$self->{"password"}
Truth table0%0/2
A
A= $self->{"password"}
Aresult
11
00
42 0 ▶ $self->{password} = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
43 0 ▶ return $self->userinfo($self->username . $self->password ? ':' . $self->password : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->username . $self->password ? : 0 0 0
44 }
45  
46 sub username {
47 0 ▶ my $self = shift;
Subroutine username: not called CC=5 SCAR=34.0
Pod documented
48 0 ▶ return $self->{username} // '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
Condition0%0/2
$self->{"username"} // ""
l!l
00
MC/DC0%0/1
$self->{"username"} // ""
$self->{"username"}
Truth table0%0/2
A
A= $self->{"username"}
Aresult
11
00
49 0 ▶ $self->{username} = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
50 0 ▶ return $self->userinfo($self->username . $self->password ? ':' . $self->password : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->username . $self->password ? : 0 0 0
51 }
52  
53 sub dsn {
54 0 ▶ my $self = shift;
Subroutine dsn: not called CC=3 SCAR=24.8
Pod documented
55 0 my $dsn = 'dbi:mysql:dbname=' . $self->database;
56 0 ▶ $dsn .= ';host=' . $self->host if $self->host;
Branch: 1 branch
BranchTrueFalseTotal
if $self->host 0 0 0
57 0 ▶ $dsn .= ';port=' . $self->port if $self->port;
Branch: 1 branch
BranchTrueFalseTotal
if $self->port 0 0 0
58 0 return $dsn;
59 }
60  
61 1 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<Mojo::MySQL5::URL> implements MySQL Connection string URL for using in L<Mojo::MySQL5>.
95
96 =head1 ATTRIBUTES
97
98 L<Mojo::MySQL5::URL> inherits all attributes from L<Mojo::URL> 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<Mojo::MySQL5::URL> inherits all methods from L<Mojo::URL> 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<DBI> 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<Mojo::MySQL5>, L<Mojo::URL>.
157  
158 =cut
« MySQL5/Database.pm ↑ Summary MySQL5/Results.pm »