| 1 | package Google::Spreadsheet::Agent::DB; | ||||||||||||
| 2 | |||||||||||||
| 3 | 25 | ▶ | use FindBin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 25 | ▶ | use YAML::Any qw/LoadFile/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 25 | ▶ | use Net::Google::Spreadsheets; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 25 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 25 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 25 | our $VERSION = '0.02'; | |||||||||||
| 10 | |||||||||||||
| 11 | 25 | has 'config_file' => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | isa => 'Str', | ||||||||||||
| 14 | ); | ||||||||||||
| 15 | |||||||||||||
| 16 | 25 | has 'config' => ( | |||||||||||
| 17 | is => 'ro', | ||||||||||||
| 18 | builder => '_build_config' | ||||||||||||
| 19 | ); | ||||||||||||
| 20 | |||||||||||||
| 21 | 25 | has 'google_db' => ( | |||||||||||
| 22 | is => 'ro', | ||||||||||||
| 23 | builder => '_build_google_db', | ||||||||||||
| 24 | lazy => 1, # depends on config | ||||||||||||
| 25 | init_arg => undef # google_db cannot be overridden | ||||||||||||
| 26 | ); | ||||||||||||
| 27 | |||||||||||||
| 28 | #### BUILDERS | ||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||
| 32 | |||||||||||||
| 33 | 0 | my @required_key_fields = grep { $self->config->{key_fields}->{$_}->{required} } keys %{$self->config->{key_fields}}; | |||||||||||
| 34 | 0 | ▶ | croak "Your configuration must have at least one required key_fields key!\n" unless (@required_key_fields); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | sub _build_config { | ||||||||||
|
Subroutine
_build_config: not called CC=3 SCAR=24.8
| |||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||
| 39 | 0 | ▶ | my $config_file = $self->config_file || $FindBin::Bin.'/../config/agent.conf.yml'; | ||||||||||
|
Condition0%0/2
$self->config_file || $FindBin::Bin . '/../config/agent.conf.yml'
MC/DC0%0/1
$self->config_file || $FindBin::Bin . '/../config/agent.conf.yml'
$self->config_file
Truth table0%0/2
A
A= $self->config_file
| |||||||||||||
| 40 | 0 | ▶ | croak "Config ${config_file} not found!\n" unless (-e $config_file); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | return YAML::Any::LoadFile($config_file); | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 0 | ▶ | sub _build_google_db { | ||||||||||
|
Subroutine
_build_google_db: not called CC=1 SCAR=6.9
| |||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||
| 46 | my $service = Net::Google::Spreadsheets->new( | ||||||||||||
| 47 | username => $self->config->{guser}, | ||||||||||||
| 48 | password => $self->config->{gpass}, | ||||||||||||
| 49 | 0 | ); | |||||||||||
| 50 | return $service->spreadsheet({ | ||||||||||||
| 51 | title => $self->config->{spreadsheet_name} | ||||||||||||
| 52 | 0 | }); | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 25 | 1; # End of Google::Spreadsheet::Agent::DB | |||||||||||
| 56 | |||||||||||||
| 57 | __END__ | ||||||||||||