This file is indexed.

/usr/share/perl5/Config/Pit.pm is in libconfig-pit-perl 0.04-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package Config::Pit;

use strict;
use 5.8.1;

use base qw/Exporter/;
our @EXPORT = qw/pit_get pit_set pit_switch/;

*pit_get    = \&get;
*pit_set    = \&set;
*pit_switch = \&switch;

use YAML::Syck;
use Path::Class;
use File::HomeDir;
use File::Spec;
use File::Temp;
use List::MoreUtils qw(all);

our $VERSION      = '0.04';
our $directory    = dir(File::HomeDir->my_home, ".pit");
our $config_file  = $directory->file("pit.yaml");
our $profile_file = undef;
our $verbose      = 1;

sub get {
	my ($name, %opts) = @_;
	my $profile = _load();
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	if ($opts{require}) {
		unless (all { defined $profile->{$name}->{$_} } keys %{$opts{require}}) {
			# merge
			my %t = (%{$opts{require}}, %{$profile->{$name}});
			$profile->{$name} = set($name, config => \%t);
		}
	}
	return $profile->{$name} || {};
}

sub set {
	my ($name, %opts) = @_;
	my $result = {};
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	if ($opts{data}) {
		$result = $opts{data};
	} else {
		return {} unless $ENV{EDITOR};
		my $setting = $opts{config} || get($name);
		# system
		my $f = File::Temp->new(SUFFIX => ".yaml");
		print $f YAML::Syck::Dump($setting);
		close $f;
		my $t = file($f->filename)->stat->mtime;
		system $ENV{EDITOR}, $f->filename;
		if ($t == file($f->filename)->stat->mtime) {
			print STDERR "No changes." if $verbose;
			$result = get($name);
		} else {
			$result = set($name, data => YAML::Syck::LoadFile($f->filename));
		}
	}
	my $profile = _load();
	$profile->{$name} = $result;
	YAML::Syck::DumpFile($profile_file, $profile);
	return $result;
}

sub switch {
	my ($name, %opts) = @_;
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	$name ||= "default";

	$profile_file = File::Spec->catfile($directory, "$name.yaml");

	my $config = _config();
	my $ret = $config->{profile};
	$config->{profile} = $name;
	YAML::Syck::DumpFile($config_file, $config);
	print STDERR "Config::Pit: Profile switch to $name from $ret.\n" if $verbose && ($name ne $ret);
	return $ret;
}

sub pipe {
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	-t STDOUT ? print STDERR 'do not output to tty.' :  print Dump(get(shift)), "\n"; ## no critic
}

sub _load {
	my $config = _config();
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	switch($config->{profile});

	unless (-e $profile_file) {
		YAML::Syck::DumpFile($profile_file, {});
	}
	return YAML::Syck::LoadFile($profile_file);
}

sub _config {
	local $YAML::Syck::ImplicitTyping = 1;
	local $YAML::Syck::SingleQuote    = 1;

	(-e $directory) || $directory->mkpath(0, 0700);

	my $config = eval { YAML::Syck::LoadFile($config_file) } || ({
		profile => "default"
	});
	return $config;
}


1;
__END__

=head1 NAME

Config::Pit - Manage settings

=head1 SYNOPSIS

  use Config::Pit;

  my $config = pit_get("example.com", require => {
    "username" => "your username on example",
    "password" => "your password on example"
  });
  # if the fields are not set, open setting by $EDITOR
  # with YAML-dumped default values (specified at C<require>).

  # use $config->{username}, $config->{password}

=head1 DESCRIPTION

Config::Pit is account setting management library.
This library automates editing settings used in scripts.

Original library is written in Ruby and published as pit gem with management command.

You can install it by rubygems:

  $ sudo gem install pit
  $ pit set example.com
  # open setting of example.com with $EDITOR.

And Config::Pit provides ppit command which is pit command written in Perl.

See:

  $ ppit help

=head1 FUNCTIONS

=head2 Config::Pit::get(setting_name, opts)

Get setting named C<setting_name> from current profile.

  my $config = Config::Pit::get("example.com");

This is same as below:

  my $config = pit_get("example.com");

opts:

=over

=item B<require>

Specify fields you want as key and hint (description or default value) of the field as value.

  my $config = pit_get("example.com", require => {
    "username" => "your username on example.com",
    "password" => "your password on example.com"
  });

C<require> specified, module check the required fields all exist in setting.
If not exist, open the setting by $EDITOR with merged setting with current setting.

=back

=head2 Config::Pit::set(setting_name, opts)

Set setting named C<setting_name> to current profile.

  Config::Pit::set("example.com"); #=> will open setting with $EDITOR

opts:

=over

=item B<data>

  Config::Pit::set("example.com", data => {
    username => "foobar",
    password => "barbaz",
  });

When C<data> specified, will not open C<$EDITOR> and set the data directly.

=item B<config>


  Config::Pit::set("example.com", config => {
    username => "config description or default value",
    password => "same as above",
  });

Open C<$EDITOR> with merged setting with specified config.

=back

=head2 Config::Pit::switch(profile_name);

Switch profile to C<profile_name>.

Profile is setting set:

  $ pit get foobar
  # foo bar...

  $ pit switch devel
  Switch profile to devel

  $ pit get foobar
  # bar baz

  $ pit switch
  Switch profile to default

  $ pit get foobar
  # foo bar...

=head1 AUTHOR

cho45 E<lt>cho45@lowreal.netE<gt>

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<http://lowreal.rubyforge.org/pit/> is pit in Ruby.

F<bin/ppit> is pit command in Perl.

=cut