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   25201 use Moose::Role;
  37         4397  
  37         485  
6 37     37   216459 use MooseX::Types::Moose qw(HashRef);
  37         51720  
  37         532  
7              
8 37     37   188622 use Pinto::Globals;
  37         147  
  37         788  
9 37     37   1657 use Pinto::Types qw(File);
  37         108  
  37         315  
10 37     37   245960 use Pinto::Util qw(current_author_id);
  37         105  
  37         2470  
11              
12 37     37   521 use Path::Class;
  37         117  
  37         1822  
13 37     37   17565 use File::HomeDir;
  37         122150  
  37         11295  
14              
15             #------------------------------------------------------------------------------
16              
17             our $VERSION = '0.13'; # 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         68 my $cfg = {};
55 22 100       601 return $cfg if $Pinto::Globals::current_author_id;
56 1 50       23 return $cfg if not -e $self->pauserc();
57 1         137 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         188 while (<$fh>) {
63 5 100       23 next if /^ \s* (?: [#].*)? $/x;
64 3         18 my ( $k, $v ) = /^ \s* (\w+) \s+ (.+?) \s* $/x;
65 3 100       14 next unless $k;
66 2         9 $cfg->{$k} = $v;
67             }
68              
69 1         38 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.13
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