App-BCVI
view release on metacpan or search on metacpan
}
sub set_opt {
my($self, $key, $value) = @_;
return $self->{_options}->{$key} = $value;
}
sub dispatch_option {
my($self) = @_;
my @set;
$self->each_option(sub {
my($o) = @_;
push @set, $o if $o->{dispatch_to} && defined $self->opt($o->{name});
});
return unless @set;
if(@set > 1) {
@set = map { "--$_->{name}" } @set;
my $last = pop @set;
$self->die_synopsis(
"Which did you want: " . join(', ', @set) . " or $last?"
);
}
return $set[0]->{dispatch_to};
}
sub default_port {
return( ($< * 10 + 9) % 65536 );
}
sub listen_address {
return 'localhost';
};
sub default_command {
return 'vi';
}
sub read_file {
my($self, $path) = @_;
return unless -e $path;
return if -d $path;
my $data = do {
open my $fh, '<', $path or die "open($path): $!\n";
local($/) = undef;
<$fh>;
};
return $data;
}
sub home_directory {
return (getpwuid($>))[7];
}
sub conf_directory {
my($self) = @_;
my $conf_dir = File::Spec->catdir($self->home_directory(), '.config', 'bcvi');
File::Path::mkpath($conf_dir) unless -d $conf_dir;
return $conf_dir;
}
sub auth_key_filename {
return File::Spec->catfile(shift->conf_directory(), 'listener_key');
}
sub listener_port_filename {
return File::Spec->catfile(shift->conf_directory(), 'listener_port');
}
sub get_listener_auth_key {
my($self) = @_;
my $auth_file = $self->auth_key_filename();
my $auth_key = $self->read_file($auth_file)
or die "Auth key file does not exist: $auth_file";
chomp($auth_key);
return $auth_key;
}
sub list_plugins {
my($self) = @_;
my @plugins;
foreach my $name (sort keys %plugin_loaded) {
my $path = $plugin_loaded{$name};
$name =~ s{[.]pm$}{};
if(my $title = $self->pod_class->extract_title($path)) {
push @plugins, "$name - $title";
}
else {
push @plugins, "$name - no documentation";
}
}
return @plugins;
}
sub plugin_help {
my($self) = @_;
my $plugin = $self->opt('plugin-help');
if(my $path = $plugin_loaded{"${plugin}.pm"}) {
$self->pod_class->show_plugin_help($path);
}
else {
die "Can't find plugin: '$plugin'\n";
( run in 2.104 seconds using v1.01-cache-2.11-cpan-995e09ba956 )