File: utils.pm

package info (click to toggle)
libcpan-mini-inject-perl 1.012-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 732; makefile: 4
file content (57 lines) | stat: -rw-r--r-- 910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;

use Carp ();
use Data::Dumper;

sub global_config_exists {
  return scalar grep { -r } qw(/usr/local/etc/mcpani /etc/mcpani);
}


sub has_modes {
	$^O !~ /^MSWin|^cygwin/
	}

sub mode {
	(stat $_[0])[2] & 07777;
	}

sub write_config {
	my %defaults = qw(
		local       t/local/CPAN
		remote      http://localhost:11027
		repository: t/local/MYCPAN
		dirmode     0775
		passive     yes
		);
	my %args = (%defaults, @_);

	my $fh;
	unless( defined $args{file} ) {
		( $fh, $args{file} ) = File::Temp::tempfile();
		}

	unless( defined $fh ) {
		open $fh, '>', $args{file} or do {
			Carp::carp "Could not open <$args{file}>: $!";
			return;
			};
		}

	my $contents = <<"HERE";
local:      $args{local}
remote:     $args{remote}
repository: $args{repository}
dirmode:    $args{dirmode}
passive:    $args{passive}
HERE


	print {$fh} $contents;
	close $fh;

	return $args{file};
	}

1;