File Coverage

blib/lib/App/Toodledo/InfoCache.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 26 26 100.0


line stmt bran cond sub pod time code
1             package App::Toodledo::InfoCache;
2              
3 8     8   51 use Moose;
  8         16  
  8         72  
4 8     8   53373 use MooseX::Method::Signatures;
  8         20  
  8         94  
5 8     8   1782 use YAML qw(LoadFile DumpFile);
  8         18  
  8         565  
6 8     8   3097 use App::Toodledo::Util qw(debug);
  8         24  
  8         504  
7 8     8   53 use Log::Log4perl;
  8         17  
  8         82  
8             with 'MooseX::Log::Log4perl';
9              
10             has filename => ( is => 'rw', isa => 'Str', );
11             has password_ref => ( is => 'rw', isa => 'HashRef[Str]',
12             default => sub { {} } );
13             has app_token_ref => ( is => 'rw', isa => 'HashRef[Str]',
14             default => sub { {} } );
15             has default_user_id => ( is => 'rw', isa => 'Str' );
16              
17              
18 8     8   551692 method new_from_file ( $class: Str $file! ) {
19             if ( -r $file && -f $file)
20             {
21             my $ref = LoadFile( $file );
22             my ($password_ref, $app_token_ref, $default_user_id)
23             = @{$ref}{qw(passwords app_tokens default_user_id)};
24             my $log = Log::Log4perl->get_logger();
25             $log->debug("Loaded info cache from $file");
26             return $class->new( filename => $file,
27             password_ref => $password_ref,
28             app_token_ref => $app_token_ref,
29             default_user_id => $default_user_id );
30             }
31             else
32             {
33             return $class->new( filename => $file );
34             }
35             }
36              
37              
38 8     8   382465 method save_to_file ( Str $filename! ) {
39             my %params = ( passwords => $self->password_ref,
40             app_tokens => $self->app_token_ref,
41             default_user_id => $self->default_user_id );
42             DumpFile( $filename, \%params );
43             }
44              
45              
46 8     8   180812 method save () {
47             $self->log->debug("test");
48             $self->save_to_file( $self->filename );
49             }
50              
51              
52             1;
53              
54             __END__
55              
56             =head1 NAME
57              
58             =head1 SYNOPSIS
59              
60             =head1 DESCRIPTION
61              
62             Store information for making calls easier. Used for storing
63             username => password mapping and app_id => app_token mappings.
64              
65             =head1 AUTHOR
66              
67             Peter Scott C<cpan at psdt.com>
68              
69             =cut