/usr/share/perl5/Kwiki/Command.pm is in libkwiki-perl 0.39-2.
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | package Kwiki::Command;
use Spoon::Command -Base;
sub handle_new {
$self->assert_directory(shift, 'Kwiki');
$self->add_new_default_config;
$self->install('files');
$self->install('config');
$self->create_registry;
# XXX a method should return this list of plugin class_ids
$self->install('display');
$self->install('edit');
$self->install('formatter');
$self->install('users');
$self->install('pages');
$self->install('theme');
$self->install('toolbar');
$self->install('status');
$self->install('widgets');
io('plugin')->mkdir;
$self->set_permissions;
$self->handle_update_all;
warn "\nKwiki software installed! Point your browser at this location.\n\n";
}
sub handle_new_view {
$self->assert_directory(shift, 'kwiki view');
die "Parent directory does not look like a Kwiki installation"
unless -e '../plugins';
require Cwd;
my $home = Cwd::cwd();
$home =~ s/.*\///;
for my $file (io->updir->all) {
my $name = $file->filename;
next if $name eq '.htaccess';
next if $name eq 'plugins';
next if $name eq 'registry.dd';
next if $name eq $home;
io->link($name)->symlink($file->name);
}
$self->create_new_view_plugins;
$self->handle_update;
print <<END;
New view created. Now edit the $home/plugins file and run
'kwiki -update' in the '$home' subdirectory.
END
}
sub create_new_view_plugins {
io('plugins')->print(<<END);
# You can either list all the plugins you want manually, or put '+' and '-' in
# front of the plugins you want to add/remove from ../plugins respectively.
#
# Example:
#
# -Kwiki::Edit
# +Kwiki::Favorites
# +Kwiki::Weather
END
}
sub assert_directory {
chdir io->dir(shift || '.')->assert->open->name;
my $noun = shift;
die "Can't make new $noun in a non-empty directory\n"
unless io('.')->empty;
}
sub add_new_default_config {
$self->hub->config->add_config(
{
display_class => 'Kwiki::Display',
edit_class => 'Kwiki::Edit',
files_class => 'Kwiki::Files',
theme_class => 'Kwiki::Theme::Basic',
toolbar_class => 'Kwiki::Toolbar',
status_class => 'Kwiki::Status',
widgets_class => 'Kwiki::Widgets',
}
);
}
sub install {
my $class_id = shift;
my $object = $self->hub->$class_id
or return;
return unless $object->can('extract_files');
my $class_title = $self->hub->$class_id->class_title;
$self->msg("Extracting files for $class_title:\n");
$self->hub->$class_id->quiet($self->quiet);
$self->hub->$class_id->extract_files;
$self->msg("\n");
}
sub is_kwiki_dir {
my $dir = shift || '.';
-d "$dir/plugin" and -f "$dir/registry.dd";
}
sub handle_update {
chdir io->dir(shift || '.')->assert->open . '';
die "Can't update non Kwiki directory!\n"
unless -d 'plugin';
$self->create_registry;
$self->install($_) for $self->all_class_ids;
$self->set_permissions;
}
sub handle_update_all {
my @dirs = (io->curdir, io->curdir->All_Dirs);
while (my $dir = shift @dirs) {
next unless $self->is_kwiki_dir($dir);
$self->msg('Updating ', $dir->absolute->pathname, "\n");
$dir->chdir;
system("kwiki -quiet -update");
}
}
sub all_class_ids {
my @all_modules;
for my $key (keys %{$self->hub->config}) {
push @all_modules, $self->hub->config->{$key}
if $key =~ /_class/;
}
push @all_modules, @{$self->hub->config->{plugin_classes} || []};
map {
eval "require $_; 1"
? $_->can('extract_files')
? do {
my $class_id = $_->class_id;
$self->hub->config->add_config({"${class_id}_class" => $_});
($_->class_id)
}
: ()
: ();
} @all_modules;
}
sub handle_add {
$self->update_plugins('+', @_);
}
sub handle_remove {
$self->update_plugins('-', @_);
}
sub update_plugins {
die "This operation must be performed inside a Kwiki installation directory"
unless -f $self->hub->config->plugins_file;
my $mode = shift;
return $self->usage unless @_;
my $plugins_file = $self->hub->config->plugins_file;
my $plugins = io($plugins_file);
my @lines = $plugins->chomp->slurp;
for my $module (@_) {
eval "require $module;1" or die $@ or
($module = "Kwiki::$module" and eval "require $module;1") or
die "Invalid module '$module'";
if ($mode eq '+') {
next if grep /^$module$/, @lines;
push @lines, $module;
next;
}
@lines = grep {$_ ne $module} @lines;
}
$plugins->println($_) for @lines;
$plugins->close;
$self->hub->config->add_plugins_file($plugins_file);
$self->handle_update;
}
sub handle_install {
die "This operation must be performed inside a Kwiki installation directory"
unless -f $self->hub->config->plugins_file;
return $self->usage unless @_;
require Cwd;
$self->cpan_setup;
my @modules = @_;
for my $module (@_) {
$self->fake_install($module);
my $home = Cwd::cwd();
my $rc = CPAN::Shell->expand('Module', $module);
if (not defined $rc) {
die "WARNING - Can't install $module\nStopping...\n";
}
$rc->install;
chdir $home;
}
$self->update_plugins('+', @modules);
}
sub cpan_setup {
no warnings;
require CPAN;
# require CPAN::Config;
my $lib = io->dir('lib')->absolute;
$ENV{PERL_MM_OPT} = "INSTALLSITELIB=$lib PREFIX=$lib"
if $lib->exists;
CPAN::Config->load;
$CPAN::Config_loaded = 1;
my $cpan_dir = io->dir('.cpan')->rel2abs;
$CPAN::Config->{cpan_home} =
$CPAN::Config->{build_dir} = $cpan_dir;
$CPAN::Config->{keep_source_where} =
io->catdir($cpan_dir, 'sources')->name;
}
sub fake_install {
return unless -d 'lib';
my $module = shift;
$module =~ s/::/\//g;
$module .= '.pm';
my $file = io->catfile('lib', $module);
$file->assert->touch
unless -f $file->name;
}
sub handle_compress {
require Spoon::Installer;
Spoon::Installer->new->compress_lib(@_);
}
sub set_permissions {
my $umask = umask 0000;
chmod 0777, qw(database plugin);
chmod 0666, qw(database/HomePage);
chmod 0755, qw(index.cgi);
umask $umask;
}
sub create_registry {
my $registry = $self->hub->registry;
my $registry_path = $registry->registry_path;
$self->msg("Generating Kwiki Registry '$registry_path'\n");
$registry->update;
if ($registry->validate) {
$registry->write;
}
$self->hub();
$self->hub->registry->load;
}
sub usage {
warn <<END . $self->command_usage(" kwiki -%-20s # %s\n");
usage:
kwiki -new [path] # Generate a new Kwiki
kwiki -update [path] # Update an existing Kwiki
kwiki -add Kwiki::Foo # Add a plugin
kwiki -remove Kwiki::Foo # Remove a plugin
kwiki -install Kwiki::Foo # Download and install a plugin
kwiki -new_view [subdir] # Create a new view under an existing Kwiki
kwiki -update_all # Update all Kwiki dirs under current dir
END
}
__DATA__
=head1 NAME
Kwiki::Command - Kwiki Command Line Tool Module
=head1 SYNOPSIS
> kwiki -new mykwiki
> cd mykwiki
> kwiki -install Kwiki::RecentChanges Kwiki::Archive::Rcs Kwiki::Revisions
> vim config.yaml
> kwiki -update
> kwiki -remove RecentChanges
> kwiki -new_view admin
=head1 DESCRIPTION
Kwiki::Command is the module that does all the work of the C<kwiki>
command line tool. You can use C<kwiki> to install a new Kwiki, to
update a Kwiki configuration, to add and remove Kwiki plugins and to
download Kwiki plugins from CPAN. When you download the CPAN modules
they can either be installed in the system Perl libraries or locally
right in your kwiki dist. This is useful if you don't have root
permissions for your installation.
=head1 USAGES
There are many different commands you can do with the C<kwiki> command line
tool.
=over 4
=item * -new
Create a new kwiki with the command:
kwiki -new
You must be inside an empty directory. Alternatively you can say:
kwiki -new path/to/kwiki
The target directory must be empty or must not exist yet.
=back
=head1 AUTHOR
Brian Ingerson <INGY@cpan.org>
=head1 COPYRIGHT
Copyright (c) 2004. Brian Ingerson. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
=cut
|