| 1 | # ABSTRACT: Something that has a pause config attribute | ||||||||||
| 2 | |||||||||||
| 3 | package Pinto::Role::PauseConfig; | ||||||||||
| 4 | |||||||||||
| 5 | 39 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 39 | ▶ | use MooseX::Types::Moose qw(HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 39 | ▶ | use Pinto::Globals; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 39 | ▶ | use Pinto::Types qw(File); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 39 | ▶ | use Pinto::Util qw(current_author_id); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 39 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 39 | ▶ | use File::HomeDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | #------------------------------------------------------------------------------ | ||||||||||
| 16 | |||||||||||
| 17 | 39 | our $VERSION = '0.14'; # VERSION | |||||||||
| 18 | |||||||||||
| 19 | #------------------------------------------------------------------------------ | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 39 | has pauserc => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | isa => File, | ||||||||||
| 25 | lazy => 1, | ||||||||||
| 26 | coerce => 1, | ||||||||||
| 27 | builder => '_build_pauserc', | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | #------------------------------------------------------------------------------ | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | 39 | has pausecfg => ( | |||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | isa => HashRef, | ||||||||||
| 36 | lazy => 1, | ||||||||||
| 37 | init_arg => undef, | ||||||||||
| 38 | builder => '_build_pausecfg', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | #------------------------------------------------------------------------------ | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub _build_pauserc { | ||||||||
|
Subroutine
_build_pauserc: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | 0 | my ($self) = @_; | |||||||||
| 45 | |||||||||||
| 46 | 0 | return file( File::HomeDir->my_home, '.pause' ); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | #------------------------------------------------------------------------------ | ||||||||||
| 50 | |||||||||||
| 51 | 23 | ▶ | sub _build_pausecfg { | ||||||||
|
Subroutine
_build_pausecfg: called CC=6 SCAR=17.9
| |||||||||||
| 52 | 23 | my ($self) = @_; | |||||||||
| 53 | |||||||||||
| 54 | 23 | my $cfg = {}; | |||||||||
| 55 | 23 | ▶ | return $cfg if $Pinto::Globals::current_author_id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | ▶ | return $cfg if not -e $self->pauserc(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | 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 | ▶ | while (<$fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 5 | ▶ | next if /^ \s* (?: [#].*)? $/x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 3 | my ( $k, $v ) = /^ \s* (\w+) \s+ (.+?) \s* $/x; | |||||||||
| 65 | 3 | ▶ | next unless $k; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 2 | $cfg->{$k} = $v; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | return $cfg; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | #------------------------------------------------------------------------------ | ||||||||||
| 73 | 39 | 1; | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||