line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::FogBugz::Config; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
19517
|
use strict; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
278
|
|
4
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
392
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.2'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
9
|
|
|
|
|
|
|
# Library Modules |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
34
|
use base qw(Class::Accessor::Fast); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3885
|
|
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
22625
|
use IO::File; |
|
7
|
|
|
|
|
56886
|
|
|
7
|
|
|
|
|
3770
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
# Variables |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %NAMES = ( |
19
|
|
|
|
|
|
|
'URL' => 'base_url', |
20
|
|
|
|
|
|
|
'TOKEN' => 'token', |
21
|
|
|
|
|
|
|
'EMAIL' => 'email', |
22
|
|
|
|
|
|
|
'PASSWORD' => 'password' |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
# Accessors |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(base_url token email password file); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
# Public API |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
3
|
|
|
3
|
1
|
6398
|
my $class = shift; |
35
|
3
|
|
|
|
|
13
|
my ($params) = {@_}; |
36
|
3
|
|
|
|
|
5
|
my $atts = {}; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
7
|
my $self = bless $atts, $class; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
10
|
my $fbrc = $params->{config}; |
41
|
3
|
|
66
|
|
|
11
|
$fbrc ||= $ENV{FBRC}; |
42
|
3
|
100
|
66
|
|
|
66
|
$fbrc = '.fbrc' unless($fbrc && -f $fbrc); |
43
|
3
|
100
|
66
|
|
|
35
|
$fbrc = "$ENV{HOME}/.fbrc" unless($fbrc && -f $fbrc); |
44
|
3
|
100
|
66
|
|
|
28
|
$fbrc = '' unless($fbrc && -f $fbrc); |
45
|
|
|
|
|
|
|
|
46
|
3
|
100
|
|
|
|
12
|
$self->readConfig($fbrc) if($fbrc); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
39
|
my %config; |
49
|
3
|
|
|
|
|
6
|
for my $key (qw(token email password base_url)) { |
50
|
12
|
|
100
|
|
|
60
|
$config{$key} = $params->{$key} || $self->{$key}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
3
|
50
|
|
|
|
17
|
$self->base_url($config{base_url}) if($config{base_url}); |
54
|
3
|
100
|
|
|
|
27
|
$self->token( $config{token}) if($config{token}); |
55
|
3
|
100
|
|
|
|
16
|
$self->email( $config{email}) if($config{email}); |
56
|
3
|
100
|
|
|
|
15
|
$self->password($config{password}) if($config{password}); |
57
|
3
|
100
|
|
|
|
15
|
$self->file( $fbrc) if($fbrc); |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
20
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub readConfig { |
63
|
2
|
|
|
2
|
1
|
5
|
my ($self, $fbrc) = @_; |
64
|
2
|
50
|
33
|
|
|
38
|
return unless(-f $fbrc && -r $fbrc); |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
17
|
my $fh = IO::File->new($fbrc,'r'); |
67
|
2
|
50
|
|
|
|
219
|
return unless($fh); |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
3
|
my $line; |
70
|
2
|
|
|
|
|
25
|
while( defined($line = <$fh>) ) { |
71
|
5
|
|
|
|
|
22
|
$line =~ s!\s+$!!; |
72
|
5
|
50
|
33
|
|
|
31
|
next unless($line && $line !~ /^#/); |
73
|
5
|
|
|
|
|
15
|
$line =~ s/^\s*//; |
74
|
5
|
50
|
|
|
|
24
|
if($line =~ /^(URL|TOKEN|EMAIL|PASSWORD)\s*=\s*(.*)/) { |
75
|
5
|
|
|
|
|
37
|
$self->{ $NAMES{$1} } = $2; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
13
|
$fh->close; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |