| 1 | use 5.014; # because we use the 'state' and 'non-destructive substitution' feature (s///r) | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package Banal::Dist::Util::Pause; | ||
| 6 | # vim: set ts=2 sts=2 sw=2 tw=115 et : | ||
| 7 | # ABSTRACT: General purpose utility collection for <Dist::Zilla::*::Author::TABULO> | ||
| 8 | # KEYWORDS: author utility | ||
| 9 | |||
| 10 | our $VERSION = '0.005'; | ||
| 11 | # AUTHORITY | ||
| 12 | |||
| 13 | use Path::Tiny; | ||
| 14 | use namespace::autoclean; | ||
| 15 | |||
| 16 | use Exporter::Shiny qw( | ||
| 17 | pause_config | ||
| 18 | ); | ||
| 19 | |||
| 20 | # return username, password from ~/.pause | ||
| 21 | sub pause_config | ||
| 22 | { | ||
| 23 | # my $home = $ENV{HOME}; | ||
| 24 | # return unless defined $home; | ||
| 25 | # my $file = path($home, '.pause')->realpath; | ||
| 26 | # # my $file = path('~/.pause')->realpath; | ||
| 27 | # return unless $file->exists(); | ||
| 28 | |||
| 29 | my %r; | ||
| 30 | FILE: | ||
| 31 | foreach my $fname (qw(~/.pause ~/.pause.conf)) { | ||
| 32 | my $file = path($fname)->realpath; | ||
| 33 | next FILE unless $file->exists; | ||
| 34 | LINE: | ||
| 35 | foreach ( $file->lines(chomp=>1) ) { | ||
| 36 | KEY: | ||
| 37 | foreach my $key (qw(user password)) { | ||
| 38 | m/^\s*${key}\s*(\s|[=])\s*(\S+)/ and do { $r{$key} = $1; next }; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | wantarray ? (%r) : \%r; | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | __END__ |