File Coverage

blib/lib/Pinto/Role/PauseConfig.pm
Criterion Covered Total %
statement 32 34 94.1
branch 7 8 87.5
condition n/a
subroutine 8 9 88.8
pod n/a
total 47 51 92.1


line stmt bran cond sub pod time code
1             # ABSTRACT: Something that has a pause config attribute
2              
3             package Pinto::Role::PauseConfig;
4              
5 37     37   24332 use Moose::Role;
  37         4101  
  37         455  
6 37     37   187552 use MooseX::Types::Moose qw(HashRef);
  37         49045  
  37         443  
7              
8 37     37   162729 use Pinto::Globals;
  37         104  
  37         655  
9 37     37   1356 use Pinto::Types qw(File);
  37         80  
  37         284  
10 37     37   211633 use Pinto::Util qw(current_author_id);
  37         104  
  37         2234  
11              
12 37     37   389 use Path::Class;
  37         90  
  37         1674  
13 37     37   16447 use File::HomeDir;
  37         111161  
  37         10718  
14              
15             #------------------------------------------------------------------------------
16              
17             our $VERSION = '0.14'; # VERSION
18              
19             #------------------------------------------------------------------------------
20              
21              
22             has pauserc => (
23             is => 'ro',
24             isa => File,
25             lazy => 1,
26             coerce => 1,
27             builder => '_build_pauserc',
28             );
29              
30             #------------------------------------------------------------------------------
31              
32              
33             has pausecfg => (
34             is => 'ro',
35             isa => HashRef,
36             lazy => 1,
37             init_arg => undef,
38             builder => '_build_pausecfg',
39             );
40              
41             #------------------------------------------------------------------------------
42              
43             sub _build_pauserc {
44 0     0   0 my ($self) = @_;
45              
46 0         0 return file( File::HomeDir->my_home, '.pause' );
47             }
48              
49             #------------------------------------------------------------------------------
50              
51             sub _build_pausecfg {
52 22     22   71 my ($self) = @_;
53              
54 22         58 my $cfg = {};
55 22 100       552 return $cfg if $Pinto::Globals::current_author_id;
56 1 50       23 return $cfg if not -e $self->pauserc();
57 1         80 my $fh = $self->pauserc->openr();
58              
59             # basically taken from the parsing code used by cpan-upload
60             # (maybe this should be part of the CPAN::Uploader api?)
61              
62 1         177 while (<$fh>) {
63 5 100       17 next if /^ \s* (?: [#].*)? $/x;
64 3         15 my ( $k, $v ) = /^ \s* (\w+) \s+ (.+?) \s* $/x;
65 3 100       11 next unless $k;
66 2         7 $cfg->{$k} = $v;
67             }
68              
69 1         35 return $cfg;
70             }
71              
72             #------------------------------------------------------------------------------
73             1;
74              
75             __END__
76              
77             =pod
78              
79             =encoding UTF-8
80              
81             =for :stopwords Jeffrey Ryan Thalhammer pauserc pausecfg
82              
83             =head1 NAME
84              
85             Pinto::Role::PauseConfig - Something that has a pause config attribute
86              
87             =head1 VERSION
88              
89             version 0.14
90              
91             =head1 ATTRIBUTES
92              
93             =head2 pauserc
94              
95             The path to your PAUSE config file. By default, this is F<~/.pause>.
96              
97             =head1 METHODS
98              
99             =head2 pausecfg
100              
101             Returns a hashref representing the data of the PAUSE config file.
102              
103             =head1 AUTHOR
104              
105             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =cut