diff --git a/ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm b/ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm index 69342cb416..ad5bc82310 100644 --- a/ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm +++ b/ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm @@ -148,7 +148,11 @@ sub _JSONwrap { no strict 'refs'; my $response; - eval { require Taint::Runtime; }; + eval { + local $SIG{__DIE__}; + local $SIG{__WARN__}; + require Taint::Runtime; + }; if ($@) { $response = &$method( $request->params(), $reporter ); } diff --git a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/PNOTIFY.pm b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/PNOTIFY.pm index 49480e267b..5f0d2d7443 100644 --- a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/PNOTIFY.pm +++ b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/PNOTIFY.pm @@ -1,8 +1,8 @@ # See bottom of file for license and copyright information package Foswiki::Plugins::JQueryPlugin::PNOTIFY; -use v5.14 l +use v5.14; - use Moo; +use Moo; extends qw( Foswiki::Plugins::JQueryPlugin::Plugin ); =begin TML diff --git a/UnitTestContrib/lib/Foswiki/Configure/Wizards/Test.pm b/UnitTestContrib/lib/Foswiki/Configure/Wizards/Test.pm index 8d4c9f91e7..658e7c6edb 100644 --- a/UnitTestContrib/lib/Foswiki/Configure/Wizards/Test.pm +++ b/UnitTestContrib/lib/Foswiki/Configure/Wizards/Test.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::Test; +use v5.14; =begin TML @@ -9,13 +10,10 @@ Wizard to test configure parameter passing =cut -use strict; -use warnings; - use Assert; -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +extends qw(Foswiki::Configure::Wizard); =begin TML diff --git a/core/lib/Foswiki/Configure/Checkers/Store/Implementation.pm b/core/lib/Foswiki/Configure/Checkers/Store/Implementation.pm index 7144dbb653..07f763a632 100755 --- a/core/lib/Foswiki/Configure/Checkers/Store/Implementation.pm +++ b/core/lib/Foswiki/Configure/Checkers/Store/Implementation.pm @@ -42,7 +42,7 @@ EOF eval( "Foswiki::Configure::Checkers::Store::${implementation}::Implementation->check_current_value( \$reporter )" ); - $reporter->NOTE( ref($@) ? $@->stringify : $@ ) if ($@); + $reporter->NOTE( Foswiki::Exception::errorStr($@) ) if ($@); } } diff --git a/core/lib/Foswiki/Configure/Dependency.pm b/core/lib/Foswiki/Configure/Dependency.pm index 792f7d46bd..3b9b69b52c 100644 --- a/core/lib/Foswiki/Configure/Dependency.pm +++ b/core/lib/Foswiki/Configure/Dependency.pm @@ -13,14 +13,16 @@ It is also used to examine the installed version of a Foswiki module. =cut package Foswiki::Configure::Dependency; - -use strict; -use warnings; +use v5.14; use version 0.77; use Assert; +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + my @MNAMES = qw(jan feb mar apr may jun jul aug sep oct nov dec); my $mnamess = join( '|', @MNAMES ); my $MNAME = qr/$mnamess/i; @@ -89,8 +91,8 @@ my $LAX_ALPHA_PART = qr/_[0-9]+/; my $LAX_DECIMAL_VERSION = qr/ $LAX_INTEGER_PART (?: \. | $FRACTION_PART $LAX_ALPHA_PART? )? - | - $FRACTION_PART $LAX_ALPHA_PART? + | + $FRACTION_PART $LAX_ALPHA_PART? /x; # Lax dotted-decimal version number. Distinguished by having either @@ -100,9 +102,9 @@ my $LAX_DECIMAL_VERSION = # so when there is no "v", the leading part is optional my $LAX_DOTTED_DECIMAL_VERSION = qr/ - v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )? - | - $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART? + v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )? + | + $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART? /x; # Complete lax version number syntax -- should generally be used @@ -116,6 +118,38 @@ my $LAX = qr/ $LAX_DECIMAL_VERSION | $LAX_DOTTED_DECIMAL_VERSION /x; #--------------------------------------------------------------------------# +has description => + ( is => 'rw', default => 'This module has no description.', ); +has name => ( + is => 'rw', + lazy => 1, + default => sub { + my $this = shift; + my $name; + unless ( $name = $this->module ) { + + # If {name} is defined but {module} is not, we'll have to work that + # out when we try to load the module in studyInstallation. + Foswiki::Exception::Fatal->throw( + text => "No name or module in dependency" ); + } + $name =~ s/^.*:://; + return $name; + }, +); +has module => ( is => 'rw', ); +has installed => ( is => 'rw', ); +has installedVersion => ( is => 'rw', ); +has installedRelease => ( is => 'rw', ); +has location => ( is => 'rw', ); +has notes => ( is => 'rw', default => '', ); +has trigger => ( is => 'rw', default => 1, ); +has type => ( is => 'rw', default => 'external', ); # assume external module + +# If no version condition is given, assume we will just test that the +# module is installed (any version) +has version => ( is => 'rw', default => '>=0', ); + =begin TML ---++ ClassMethod new( %opts ) @@ -139,33 +173,6 @@ Create an object instance representing a single dependency, as read from DEPENDE =cut -sub new { - my ( $class, %opts ) = @_; - my $this = bless( \%opts, $class ); - - # If {module} is defined but not {name}, we can usually work it out - if ( $this->{module} && !$this->{name} ) { - $this->{name} = $this->{module}; - $this->{name} =~ s/^.*:://; - } - - # If {name} is defined but {module} is not, we'll have to work that - # out when we try to load the module in studyInstallation. - die "No name or module in dependency" unless $this->{name}; - - # If no version condition is given, assume we will just test that the - # module is installed (any version) - $this->{version} ||= '>=0'; - - # Other defaults - $this->{trigger} ||= 1; - $this->{type} ||= 'external'; # assume external module - $this->{description} ||= 'This module has no description.'; - $this->{notes} = ''; - - return $this; -} - =begin TML ---++ ObjectMethod check() -> ($ok, $msg) @@ -181,36 +188,44 @@ sub checkDependency { my $this = shift; # reject non-Perl dependencies - if ( $this->{type} !~ /^(?:perl|cpan)$/i ) { + if ( $this->type !~ /^(?:perl|cpan)$/i ) { + my ( $module, $type ) = ( $this->module, $this->type ); return ( 0, <{module} is type '$this->{type}', and cannot be automatically checked. +${module} is type '${type}', and cannot be automatically checked. Please check it manually and install if necessary. LALA } # Examine the current install of the module if ( !$this->studyInstallation() ) { + my ( $module, $type ) = ( $this->module, $this->type ); + my ( $version, $notes ) = ( $this->version, $this->notes ); return ( 0, <{module} version $this->{version} required --- $this->{type} $this->{notes} +${module} version ${version} required +-- ${type} ${notes} TINKYWINKY } - elsif ( $this->{version} =~ m/^\s*([<>=]+)?\s*(.+)/ ) { + elsif ( $this->version =~ m/^\s*([<>=]+)?\s*(.+)/ ) { # the version field is a condition my $op = $1 || '>='; my $requiredVersion = $2; unless ( $this->compare_versions( $op, $requiredVersion ) ) { + my ( $module, $installedRelease ) = + ( $this->module, $this->installedRelease ); + # module doesn't meet this condition return ( 0, <{module} version $op $requiredVersion required --- installed version is $this->{installedRelease} +${module} version $op $requiredVersion required +-- installed version is ${installedRelease} PO } } + my ( $module, $installedRelease ) = + ( $this->module, $this->installedRelease ); return ( 1, <{module} version $this->{installedRelease} installed +${module} version ${installedRelease} installed DIPSY } @@ -232,44 +247,44 @@ sub studyInstallation { my ( $inst, $ver, $loc, $rel ); - if ( !$this->{module} ) { - my $lib = ( $this->{name} =~ m/Plugin$/ ) ? 'Plugins' : 'Contrib'; + if ( !$this->module ) { + my $lib = ( $this->name =~ m/Plugin$/ ) ? 'Plugins' : 'Contrib'; foreach my $namespace (qw(Foswiki TWiki)) { - my $path = $namespace . '::' . $lib . '::' . $this->{name}; + my $path = $namespace . '::' . $lib . '::' . $this->name; ( $inst, $ver, $loc, $rel ) = extractModuleVersion( $path, 'magic' ); if ($inst) { - $this->{module} = $path; + $this->module = $path; last; } } } else { ( $inst, $ver, $loc, $rel ) = - extractModuleVersion( $this->{module}, - $this->{module} =~ m/(?:Foswiki|TWiki)/ ); + extractModuleVersion( $this->module, + $this->module =~ m/(?:Foswiki|TWiki)/ ); } if ($inst) { - $this->{installedVersion} = $ver; - $this->{installedRelease} = $rel || $ver; - $this->{installed} = 1; - $this->{location} = $loc; + $this->installedVersion($ver); + $this->installedRelease( $rel || $ver ); + $this->installed(1); + $this->location($loc); if ( -l $loc ) { # Assume pseudo-installed - $this->{installedVersion} = '9999.99_999'; + $this->installedVersion('9999.99_999'); } } else { - $this->{notes} = "module is not installed"; - $this->{installedVersion} = ''; - $this->{installedRelease} = ''; - $this->{location} = ''; + $this->notes("module is not installed"); + $this->installedVersion(''); + $this->installedRelease(''); + $this->location(''); return 0; } - return 0 unless $this->{module}; + return 0 unless $this->module; return 1; } @@ -297,14 +312,14 @@ sub compare_using_cpan_version { sub compare_versions { my $this = shift; - if ( $this->{type} eq 'perl' ) { + if ( $this->type eq 'perl' ) { - #print STDERR "Comparing TYPE PERL $this->{module}\n" if $this->{module}; + #print STDERR "Comparing TYPE PERL ", $this->module, "\n" if $this->module; return $this->_compare_extension_versions(@_); } else { - #print STDERR "Comparing TYPE cpan $this->{module}\n"; + #print STDERR "Comparing TYPE cpan ", $this->module, "\n"; return $this->_compare_cpan_versions(@_); } } @@ -313,7 +328,7 @@ sub compare_versions { sub _compare_cpan_versions { my ( $this, $op, $b ) = @_; - my $a = $this->{installedVersion}; + my $a = $this->installedVersion; return 0 if not defined $op or not exists $STRINGOPMAP{$op}; my $string_op = $STRINGOPMAP{$op}; @@ -440,8 +455,8 @@ sub _compare_extension_versions { # $b - what we are comparing to (from DEPENDENCIES or configure FastReport) my ( $this, $op, $reqVer ) = @_; - my $aRELEASE = $this->{installedRelease}; - my $aVERSION = $this->{installedVersion}; + my $aRELEASE = $this->installedRelease; + my $aVERSION = $this->installedVersion; # If the operator is not defined, or invalid, return false if ( not defined $op or not exists $STRINGOPMAP{$op} ) { diff --git a/core/lib/Foswiki/Configure/Package.pm b/core/lib/Foswiki/Configure/Package.pm index d81dabcfb1..e39c069982 100644 --- a/core/lib/Foswiki/Configure/Package.pm +++ b/core/lib/Foswiki/Configure/Package.pm @@ -36,10 +36,9 @@ Pictorially, =cut package Foswiki::Configure::Package; +use v5.14; -use strict; -use warnings; -use Error qw(:try); +use Try::Tiny; use File::stat; # Need to import functions! use File::Copy (); use File::Spec (); @@ -51,6 +50,10 @@ use Foswiki::Configure::FileUtil (); use Foswiki::Configure::Root (); use Foswiki::Plugins (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + our $FALSE = 0; our $TRUE = 1; @@ -75,47 +78,33 @@ our $TRUE = 1; =cut -sub new { - my ( $class, %args ) = @_; - my @deps; - - ASSERT( $args{root} ) if DEBUG; - ASSERT( $args{module} ) if DEBUG; +has root => ( is => 'rw', required => 1, ); +has pkgname => ( is => 'rw', required => 1, init_arg => 'module', ); +has repository => ( is => 'rw', ); +has seen => ( is => 'rw', ); +has options => ( is => 'rw', lazy => 1, default => sub { {} }, ); - my $repo = $args{repository}; - delete $args{repository}; - my $root = $args{root}; - delete $args{root}; - my $module = $args{module}; - delete $args{module}; +has _dependencies => ( is => 'rw', lazy => 1, default => sub { [] }, ); +has _manifest => ( is => 'rw', ); +has _prepost_code => ( is => 'rw', ); +has _loaded => ( is => 'rw', ); - my $seen = $args{seen} || {}; - $seen->{$module} = 1; +around BUILDARGS => sub { + my $orig = shift; + my $class = shift; + my %params = @_; - my $this = bless( - { - _root => $root, - _pkgname => $module, - _repository => $repo, - _options => \%args, - - # Hash mapping the topics, attachment and other files - # supplied by this package - _manifest => undef, - - # Array of dependencies required by this package - _dependencies => \@deps, - _prepost_code => undef, - _loaded => undef, # Flag set if loadInstaller is complete - - # Hash of package names that have already been seen / installed - _seen => $seen, - }, - $class - ); + # Move all options into corresponding attribute. + foreach my $key ( keys %params ) { + unless ( $key =~ /^(?:root|repository|module|seen)$/ ) { + $params{options}{$key} = $params{$key}; + delete $params{$key}; + } + } + $params{seen}{ $params{module} } //= 1; - return $this; -} + return $orig->( $class, %params ); +}; =begin TML @@ -127,21 +116,11 @@ Clean up the object, releasing any memory stored in it. # Note to developers; please undef *all* fields in the object explicitly, # whether they are references or not. That way this method is "golden # documentation" of the live fields in the object. -sub finish { +sub DEMOLISH { my $this = shift; - undef $this->{_root}; - undef $this->{_pkgname}; - undef $this->{_type}; - undef $this->{_options}; - undef $this->{_manifest}; - undef $this->{_dependencies}; - undef $this->{_prepost_code}; - undef $this->{_loaded}; - for (qw( preinstall postinstall preuninstall postuninstall )) { undef &{$_}; } - } =begin TML @@ -155,21 +134,7 @@ Get module name. sub module { my ($this) = @_; - return $this->{_pkgname}; -} - -=begin TML - ----++ ObjectMethod repository() - -Get repository. - -=cut - -sub repository { - my ($this) = @_; - - return $this->{_repository}; + return $this->pkgname; } =begin TML @@ -183,8 +148,8 @@ Get or set the option associated with the object. sub option { my ( $this, $name, $value ) = @_; - $this->{_options}->{$name} = $value if scalar(@_) == 3; - return $this->{_options}->{$name}; + $this->options->{$name} = $value if scalar(@_) == 3; + return $this->options->{$name}; } { @@ -192,6 +157,10 @@ sub option { # as well as passing them to another logger. # TODO: abstract this out and share with tools/extender.pl package LoggingReporter; + use File::Spec; + use Moo; + use namespace::clean; + extends qw(Foswiki::Object); # $super - Foswiki::Configure::Reporter to pass all reports to # %options can include: @@ -201,33 +170,49 @@ sub option { # pkgname => name of package being installed # nolog => if true, don't log to file # Default name: pkgname-[action]-yyyymmdd-hhmmss.log - sub new { - my ( $class, $super, %options ) = @_; - my $this = bless( { _reporter => $super }, $class ); - if ( $options{filename} ) { - $this->{_logfile} = $options{filename}; - } - - my $action = ( defined $options{action} ) ? $options{action} : 'run'; - my $path = - ( defined $options{path} ) - ? $options{path} - : "$Foswiki::cfg{Log}{Dir}/configure"; - my $timestamp = - Foswiki::Time::formatTime( time(), - '$year$mo$day-$hours$minutes$seconds' ); - $options{pkgname} ||= ''; - $this->{_logfile} = $path . "/$options{pkgname}-$timestamp-$action.log"; - Foswiki::Configure::Load::expandValue( $this->{_logfile} ); - return $this; - } + + has reporter => ( + is => 'rw', + isa => Foswiki::Object::isaCLASS( + 'reporter', + 'Foswiki::Configure::Reporter', + noUndef => 1, + ), + required => 1, + ); + has nolog => ( is => 'rw', default => 0, ); + has logfile => ( + is => 'rw', + lazy => 1, + init_arg => 'filename', + default => sub { + my $this = shift; + my $timestamp = + Foswiki::Time::formatTime( time(), + '$year$mo$day-$hours$minutes$seconds' ); + my $logfile = File::Spec->catfile( $this->_path, + $this->_pkgname . "-$timestamp-" . $this->action . ".log" ); + $Foswiki::app->cfg->expandValue($logile); + return $logfile; + }, + ); + has _action => ( is => 'ro', init_arg => 'action', default => 'run', ); + has _path => ( + is => 'ro', + lazy => 1, + init_arg => 'path', + default => sub { + return "$Foswiki::cfg{Log}{Dir}/configure"; + }, + ); + has _pkgname => ( is => 'ro', init_arg => 'pkgname', default => '', ); sub _log { my $this = shift; use filetest 'access'; # Don't actually write any logs if simulating the install - return if $this->{nolog}; + return if $this->nolog; my $text = join( "\n", @_ ) . "\n"; @@ -237,9 +222,9 @@ sub option { # Take out active elements $text =~ s/{_logfile} ) { + unless ( -e $this->logfile ) { my @path = - split( /[\/\\]+/, $this->{_logfile}, -1 ); # -1 allows directories + split( /[\/\\]+/, $this->logfile, -1 ); # -1 allows directories pop(@path); if ( scalar(@path) ) { umask( oct(777) - $Foswiki::cfg{Store}{dirPermission} ); @@ -248,35 +233,39 @@ sub option { } } - if ( open( my $file, '>>', Foswiki::encode_utf8( $this->{_logfile} ) ) ) - { + if ( open( my $file, '>>', Foswiki::encode_utf8( $this->logfile ) ) ) { binmode $file, ":encoding(utf-8)"; print $file $text; close($file); } else { - if ( !-w $this->{_logfile} ) { - die "ERROR: Could not open logfile " - . $this->{_logfile} - . " for write. Your admin should 'configure' now and fix the errors!"; + if ( !-w $this->logfile ) { + Foswiki::Exception::Fatal->throw( + text => "ERROR: Could not open logfile " + . $this->logfile + . " for write. Your admin should 'configure' now and fix the errors!" + ); } # die to force the admin to get permissions correct - die 'ERROR: Could not write to ' . $this->{_logfile} . ": $!"; + Foswiki::Exception::Fatal->throw( + text => 'ERROR: Could not write to ' + . $this->logfile + . ": $!" ); } } sub NOTE { my $this = shift; - $this->{_reporter}->NOTE(@_); + $this->reporter->NOTE(@_); $this->_log(@_); } sub WARN { my ( $this, @p ) = @_; return unless scalar(@p); - $this->{_reporter}->WARN(@p); + $this->reporter->WARN(@p); unless ( $p[0] =~ s/^>/> *WARNING:* / ) { $p[0] = "> *WARNING:* "; } @@ -286,7 +275,7 @@ sub option { sub ERROR { my ( $this, @p ) = @_; return unless scalar(@p); - $this->{_reporter}->ERROR(@p); + $this->reporter->ERROR(@p); unless ( $p[0] =~ s/^>/> *ERROR:* / ) { $p[0] = "> *ERROR:* "; } @@ -295,21 +284,21 @@ sub option { sub CHANGED { my ( $this, $keys ) = @_; - $this->{_reporter}->CHANGED($keys); - my $val = $this->{_reporter}->{changes}->{$keys}; + $this->reporter->CHANGED($keys); + my $val = $this->reporter->{changes}->{$keys}; $this->_log("> _Changed:_ $keys = $val"); } sub WIZARD { - return shift->{_reporter}->WIZARD(@_); + return shift->reporter->WIZARD(@_); } sub messages { - return shift->{_reporter}->messages(@_); + return shift->reporter->messages(@_); } sub changes { - return shift->{_reporter}->changes(@_); + return shift->reporter->changes(@_); } } @@ -340,15 +329,15 @@ sub install { my ( $this, $supereporter, $spec ) = @_; my $reporter = LoggingReporter->new( - $supereporter, - action => 'Install', - pkgname => $this->{_pkgname}, - nolog => $this->option('SIMULATE') + reporter => $supereporter, + action => 'Install', + pkgname => $this->pkgname, + nolog => $this->option('SIMULATE') ); - $reporter->NOTE("---+ Installing $this->{_pkgname}"); + $reporter->NOTE( "---+ Installing " . $this->pkgname ); - unless ( $this->{_loaded} ) { + unless ( $this->loaded ) { # Recover the manifest from the _installer file $reporter->NOTE("> Loading package installer"); @@ -364,7 +353,8 @@ sub install { # of Dependency objects if ( $installed || $missing ) { - $reporter->NOTE("---++ Dependency Report for $this->{_pkgname} ..."); + $reporter->NOTE( + "---++ Dependency Report for " . $this->pkgname . " ..." ); $reporter->NOTE( "> *INSTALLED*", map { "\t* $_" } @$installed ) if (@$installed); $reporter->WARN( "> *MISSING*", map { "\t* $_" } @$missing ) @@ -381,7 +371,7 @@ sub install { } # Create a backup of the previous install if any - $reporter->NOTE("---+++ Creating backup of $this->{_pkgname} ..."); + $reporter->NOTE( "---+++ Creating backup of " . $this->pkgname . " ..." ); my $ok = $this->_createBackup($reporter); my %plugins; @@ -392,7 +382,8 @@ sub install { $this->_loadExits(); if ( $this->can('preinstall') && !$this->option('SIMULATE') ) { - $reporter->NOTE("> Running pre-install for $this->{_pkgname} ..."); + $reporter->NOTE( + "> Running pre-install for " . $this->pkgname . " ..." ); my $rslt = $this->preinstall(); $reporter->NOTE("$rslt") if $rslt; } @@ -403,7 +394,8 @@ sub install { if ( $this->can('postinstall') && !$this->option('SIMULATE') ) { - $reporter->NOTE("> Running post-install for $this->{_pkgname}..."); + $reporter->NOTE( + "> Running post-install for " . $this->pkgname . " ..." ); my $rslt = $this->postinstall(); $reporter->NOTE("$rslt") if $rslt; } @@ -419,9 +411,9 @@ sub install { values %$depCPAN; # merge in cpan from dependencies my $extUrl = - $Foswiki::Plugins::SESSION + $Foswiki::app ? Foswiki::Func::getScriptUrl( $Foswiki::cfg{SystemWebName}, - $this->{_pkgname}, 'view' ) + $this->pkgname, 'view' ) : ''; my $instUrl = $Foswiki::Plugins::SESSION @@ -429,6 +421,7 @@ sub install { 'InstalledPlugins', 'view' ) : ''; + my $pkgname = $this->pkgname; $reporter->NOTE( < Before proceeding, review the dependency reports of each installed extension and resolve any dependencies, as required. @@ -437,7 +430,7 @@ sub install { * CPAN dependencies are never automatically resolved. > After your configuration has been saved: - * Visit $this->{_pkgname} extension page + * Visit $pkgname extension page * Check InstalledPlugins to check for errors. WRAPUP @@ -549,15 +542,15 @@ HERE else { $val = eval( $node->{default} ); } - if ( $this->{simulated} ) { - $this->{reporter}->NOTE( "\t* $node->{keys} = " + if ( $this->simulated ) { + $this->reporter->NOTE( "\t* $node->{keys} = " . Foswiki::Configure::Reporter::uneval($val) ); } else { return 1 if ( eval("exists \$Foswiki::cfg$node->{keys}") ); eval("\$Foswiki::cfg$node->{keys}=\$val"); ASSERT( !$@, $@ ) if DEBUG; - $this->{reporter}->CHANGED( $node->{keys} ); + $this->reporter->CHANGED( $node->{keys} ); } return 1; } @@ -760,7 +753,7 @@ sub _getMappedWebTopic { sub _install { my ( $this, $reporter, $rootspec ) = @_; - my $dir = $this->option('DIR') || $this->{_root}; + my $dir = $this->option('DIR') || $this->root; $reporter->NOTE( "---+++ Installing " . $this->module() ); @@ -786,7 +779,7 @@ sub _install { { for my $sext (qw( .tgz .zip .TGZ .tar.gz .ZIP )) { use Cwd; - if ( -r "$sdir/$this->{_pkgname}$sext" ) + if ( -r "$sdir/" . $this->pkgname . "$sext" ) { # readable by user $ext = $sext; $dir = $sdir; @@ -798,8 +791,9 @@ sub _install { if ($ext) { $reporter->NOTE( -"> Using previously downloaded archive $dir/$this->{_pkgname}$ext" - ); + "> Using previously downloaded archive $dir/" + . $this->pkgname + . "$ext" ); } else { $reporter->WARN( @@ -811,12 +805,14 @@ sub _install { my $tmpdir; # Directory where archive was expanded my $tmpfilename; # Filename set when downloaded - if ( !$ext && $this->{_repository} ) + if ( !$ext && $this->repository ) { # no extension found - need to download the package - $reporter->NOTE( -"\t* fetching $this->{_pkgname} from $this->{_repository}->{pub} ..." - ); + $reporter->NOTE( "\t* fetching " + . $this->pkgname + . " from " + . $this->repository->{pub} + . " ..." ); ( $err, $tmpfilename ) = $this->_fetchFile('.tgz'); if ($err) { @@ -835,7 +831,7 @@ sub _install { } } - $tmpfilename = "$dir/$this->{_pkgname}$ext" if ($ext); + $tmpfilename = "$dir/" . $this->pkgname . "$ext" if ($ext); my $sb = stat($tmpfilename); $reporter->NOTE( "> Unpacking $tmpfilename..., Size: " . $sb->size @@ -854,11 +850,14 @@ sub _install { my ($tmpext) = $tmpfilename =~ m/.*(\.[^\.]+)$/; $reporter->NOTE( -"> Saving $tmpfilename to $Foswiki::cfg{WorkingDir}/configure/download/$this->{_pkgname}$tmpext" - ); +"> Saving $tmpfilename to $Foswiki::cfg{WorkingDir}/configure/download/" + . $this->pkgname + . "$tmpext" ); $this->_moveFile( $tmpfilename, -"$Foswiki::cfg{WorkingDir}/configure/download/$this->{_pkgname}$tmpext", + "$Foswiki::cfg{WorkingDir}/configure/download/" + . $this->pkgname + . "$tmpext", undef, 1 # Force move even if simulate ); @@ -866,8 +865,8 @@ sub _install { $dir = $tmpdir; } - my $root = $this->{_root}; # Root of the foswiki installation - my $manifest = $this->{_manifest}; # Reference to the manifest + my $root = $this->root; # Root of the foswiki installation + my $manifest = $this->_manifest; # Reference to the manifest my @names = $this->_listFiles(); # Retrieve list of filenames from manifest my $ok = 1; @@ -885,7 +884,7 @@ sub _install { } # Find where it is meant to go - my $target = _mapTarget( $this->{_root}, $file ); + my $target = _mapTarget( $this->root, $file ); # Make file writable if it is read-only if ( -e $target && !-w $target && !$this->option('SIMULATE') ) { @@ -1009,8 +1008,8 @@ sub _install { my $pkgstore = "$Foswiki::cfg{WorkingDir}/configure/pkgdata"; $err = $this->_moveFile( - "$dir/$this->{_pkgname}_installer", - "$pkgstore/$this->{_pkgname}_installer" + "$dir/" . $this->pkgname . "_installer", + "$pkgstore/" . $this->pkgname . "_installer" ); if ($err) { $reporter->ERROR($err); @@ -1020,9 +1019,9 @@ sub _install { $spec->visit( _SpecChecker->new( $reporter, $this->option('SIMULATE') ) ); - $reporter->NOTE( - "> ${simulated}Installed: $this->{_pkgname}_installer to $pkgstore" - ); + $reporter->NOTE( "> ${simulated}Installed: " + . $this->pkgname + . "_installer to $pkgstore" ); } return $ok; @@ -1045,14 +1044,14 @@ sub _installAttachments { #my $attached = shift; # Count of files attached, - foreach my $key ( sort keys %{ $this->{_manifest}{ATTACH}{$webTopic} } ) { - my $file = $this->{_manifest}->{ATTACH}->{$webTopic}->{$key}; - my $tfile = _mapTarget( $this->{_root}, $file ); + foreach my $key ( sort keys %{ $this->_manifest->{ATTACH}{$webTopic} } ) { + my $file = $this->_manifest->{ATTACH}->{$webTopic}->{$key}; + my $tfile = _mapTarget( $this->root, $file ); # Attach the file if rcs checkin is needed, otherwise skip it and it will be copied later. if ( ( - $this->{_manifest}->{$file}->{ci} + $this->_manifest->{$file}->{ci} && ( -e $tfile ) # checkin requested and file exists ) || ( -e "$tfile,v" ) # or rcs file exists @@ -1070,7 +1069,7 @@ sub _installAttachments { my $attachinfo = $meta->get( 'FILEATTACHMENT', $key ); # Recover existing Metadata - $this->{_manifest}->{$file}->{I} = + $this->_manifest->{$file}->{I} = 1; # Set this to installed (assuming it all works) my $fstats = stat "$dir/$file"; my %opts; @@ -1136,7 +1135,7 @@ sub _moveFile { # into a backup file. sub _createBackup { my ( $this, $reporter ) = @_; - my $root = $this->{_root}; + my $root = $this->root; $root =~ s#\\#/#g; # Convert windows style slashes require Foswiki::Time; @@ -1145,17 +1144,18 @@ sub _createBackup { 'servertime' ); my $bkdir = "$Foswiki::cfg{WorkingDir}/configure/backup"; - my $bkname = "$this->{_pkgname}-backup-$stamp"; + my $bkname = $this->pkgname . "-backup-$stamp"; my $pkgstore .= "$bkdir/$bkname"; my $ok = 1; my @files = $this->_listFiles(1); # return list of installed files unshift( @files, -"$Foswiki::cfg{WorkingDir}/configure/pkgdata/$this->{_pkgname}_installer" - ) - if ( - -e "$Foswiki::cfg{WorkingDir}/configure/pkgdata/$this->{_pkgname}_installer" - ); + "$Foswiki::cfg{WorkingDir}/configure/pkgdata/" + . $this->pkgname + . "_installer" ) + if (-e "$Foswiki::cfg{WorkingDir}/configure/pkgdata/" + . $this->pkgname + . "_installer" ); unless ( scalar(@files) ) { # Anything to backup? $reporter->NOTE("\t* Nothing to backup"); @@ -1219,11 +1219,11 @@ sub _setPermissions { foreach my $file (@names) { # Find where it is meant to go - my $target = _mapTarget( $this->{_root}, $file ); + my $target = _mapTarget( $this->root, $file ); if ( -f $target ) { - my $mode = $this->{_manifest}->{$file}->{perms}; + my $mode = $this->_manifest->{$file}->{perms}; if ($mode) { chmod( oct($mode), $target ) @@ -1242,10 +1242,10 @@ sub _listFiles { my ( $this, $installed ) = @_; my @files; - foreach my $key ( keys( %{ $this->{_manifest} } ) ) { + foreach my $key ( keys( %{ $this->_manifest } ) ) { next if ( $key eq 'ATTACH' ); if ($installed) { - my $target = _mapTarget( $this->{_root}, $key ); + my $target = _mapTarget( $this->root, $key ); push( @files, $target ) if ( -f $target ); push( @files, "$target,v" ) if ( -f "$target,v" ); } @@ -1288,21 +1288,21 @@ sub uninstall { my @removed; my %directories; my $reporter = LoggingReporter->new( - $supereporter, - action => 'Uninstall', - nolog => $this->option('SIMULATE') + reporter => $supereporter, + action => 'Uninstall', + nolog => $this->option('SIMULATE') ); - $reporter->NOTE("---+ Uninstalling $this->{_pkgname}"); + $reporter->NOTE( "---+ Uninstalling " . $this->pkgname ); - unless ( $this->{_loaded} ) { + unless ( $this->_loaded ) { # Recover the manifest from the _installer file $reporter->NOTE("> Loading package installer"); return 0 unless $this->loadInstaller($reporter); } - $reporter->NOTE("> Creating Backup of $this->{_pkgname} ..."); + $reporter->NOTE( "> Creating Backup of " . $this->pkgname . " ..." ); # Create a backup of the previous install if any $this->_createBackup($reporter); @@ -1310,18 +1310,19 @@ sub uninstall { $this->_loadExits(); if ( $this->can('preuninstall') && !$this->option('SIMULATE') ) { - $reporter->NOTE("> Running Pre-uninstall for $this->{_pkgname} ..."); + $reporter->NOTE( + "> Running Pre-uninstall for " . $this->pkgname . " ..." ); my $rslt = $this->preuninstall(); $reporter->NOTE("$rslt") if $rslt; } # foreach file in the manifest, remove the file. - foreach my $key ( keys( %{ $this->{_manifest} } ) ) { + foreach my $key ( keys( %{ $this->_manifest } ) ) { next if ( $key eq 'ATTACH' ); # Find where it is meant to go - my $target = _mapTarget( $this->{_root}, $key ); + my $target = _mapTarget( $this->root, $key ); if ( $this->option('SIMULATE') ) { push( @removed, "simulated $target" ) if ( -f $target ); @@ -1342,7 +1343,9 @@ sub uninstall { } my $pkgdata = - "$Foswiki::cfg{WorkingDir}/configure/pkgdata/$this->{_pkgname}_installer"; + "$Foswiki::cfg{WorkingDir}/configure/pkgdata/" + . $this->pkgname + . "_installer"; unless ( $this->option('SIMULATE') ) { push( @removed, $pkgdata ); unlink $pkgdata; @@ -1368,7 +1371,8 @@ sub uninstall { } if ( $this->can('posuninstall') && !$this->option('SIMULATE') ) { - $reporter->NOTE("> Running Post-uninstall for $this->{_pkgname} ..."); + $reporter->NOTE( + "> Running Post-uninstall for " . $this->pkgname . " ..." ); my $rslt = $this->postuninstall(); $reporter->NOTE("$rslt") if $rslt; } @@ -1426,14 +1430,14 @@ Returns: sub loadInstaller { my ( $this, $reporter ) = @_; - my $temproot = $this->option('DIR') || $this->{_root}; + my $temproot = $this->option('DIR') || $this->root; my $file; my $err; my $downloadstore = "$Foswiki::cfg{WorkingDir}/configure/download"; my $pkgstore = "$Foswiki::cfg{WorkingDir}/configure/pkgdata"; - my $extension = $this->{_pkgname}; + my $extension = $this->pkgname; my $warn = ''; local $/ = "\n"; @@ -1471,7 +1475,7 @@ sub loadInstaller { . " for package manifest" ); } else { - if ( defined $this->{_repository} ) { + if ( defined $this->repository ) { $reporter->NOTE( " * fetching $extension installer from " . $this->repository()->{pub} . '...' ); @@ -1482,9 +1486,9 @@ sub loadInstaller { } } else { - $reporter->WARN( - "Unable to download $this->{_pkgname} - no repository provided" - ); + $reporter->WARN( "Unable to download " + . $this->pkgname + . " - no repository provided" ); return 0; } } @@ -1536,13 +1540,13 @@ sub loadInstaller { $depth++ for /{/g; $depth-- for /}/g; $_ =~ /^(.*)$/; # untaint - $this->{_prepost_code} .= "$1\n"; + $this->_prepost_code( $this->_prepost_code . "$1\n" ); $found = '' unless $depth; next; } } close $fh; - $this->{_loaded} = 1; + $this->_loaded(1); return 1; } @@ -1553,13 +1557,13 @@ sub _loadExits { my $this = shift; my $err = ''; - if ( $this->{_prepost_code} ) { + if ( $this->_prepost_code ) { # Ensure it's clean, to avoid redefine error for (qw( preinstall postinstall preuninstall postuninstall )) { undef &{$_}; } - unless ( eval( $this->{_prepost_code} . "; 1; " ) ) { + unless ( eval( $this->_prepost_code . "; 1; " ) ) { die "Couldn't load pre/post (un)install: $@"; } } @@ -1583,11 +1587,11 @@ sub manifest { my ($this) = @_; my $rslt = ''; - foreach my $file ( sort keys( %{ $this->{_manifest} } ) ) { + foreach my $file ( sort keys( %{ $this->_manifest } ) ) { next if ( $file eq 'ATTACH' ); $rslt .= join( " ", $file, - map { $this->{_manifest}->{$file}->{$_} } qw( perms md5 desc ) ) + map { $this->_manifest->{$file}->{$_} } qw( perms md5 desc ) ) . "\n"; } return $rslt; @@ -1675,15 +1679,15 @@ sub _parseManifest { } } - $this->{_manifest}->{$file}->{ci} = + $this->_manifest->{$file}->{ci} = ( ( !$canCheckin || $desc =~ s/\(noci\)// ) ? 0 : 1 ); - $this->{_manifest}->{$file}->{perms} = $perms; - $this->{_manifest}->{$file}->{md5} = $md5 || ''; + $this->_manifest->{$file}->{perms} = $perms; + $this->_manifest->{$file}->{md5} = $md5 || ''; # SMELL: The {topic} field isn't used by Package. But it should be. - $this->{_manifest}->{$file}->{topic} = "$tweb\t$ttopic\t$tattach"; - $this->{_manifest}->{$file}->{desc} = $desc; - $this->{_manifest}->{ATTACH}->{"$tweb/$ttopic"}->{$tattach} = $file + $this->_manifest->{$file}->{topic} = "$tweb\t$ttopic\t$tattach"; + $this->_manifest->{$file}->{desc} = $desc; + $this->_manifest->{ATTACH}->{"$tweb/$ttopic"}->{$tattach} = $file if $tattach; } @@ -1711,7 +1715,7 @@ sub _parseDependency { # ONLYIF can be arbitrary perl code - but then, so can the # extension. DEPENDENCIES files should be as secure as .pms. push( - @{ $this->{_dependencies} }, + @{ $this->_dependencies }, new Foswiki::Configure::Dependency( module => $module, type => $type, @@ -1759,7 +1763,7 @@ sub checkDependencies { my @cpan; my @manual; - foreach my $dep ( @{ $this->{_dependencies} } ) { + foreach my $dep ( @{ $this->_dependencies } ) { ( my $trigger ) = $dep->{trigger} =~ m/^(.*)$/s; @@ -1827,14 +1831,14 @@ sub _installDependencies { my ( $ok, $msg ) = $dep->checkDependency(); unless ($ok) { $reporter->NOTE("Skipping duplicate dependency $dep->{name}") - if ( $this->{_seen}{ $dep->{name} } ); - next if ( $this->{_seen}{ $dep->{name} } ); + if ( $this->seen->{ $dep->{name} } ); + next if ( $this->seen->{ $dep->{name} } ); my $deppkg = Foswiki::Configure::Package->new( - root => $this->{_root}, - repository => $this->{_repository}, + root => $this->root, + repository => $this->repository, module => $dep->{name}, - seen => $this->{_seen}, - %{ $this->{_options} } + seen => $this->seen, + %{ $this->_options } ); my ( $ok, $plugins, $cpan ) = $deppkg->install( $reporter, $spec ); if ($ok) { @@ -1862,14 +1866,11 @@ sub _fetchFile { my ( $this, $ext ) = @_; my $arf = - $this->{_repository}->{pub} - . $this->{_pkgname} . '/' - . $this->{_pkgname} - . $ext; - if ( defined( $this->{_repository}->{user} ) ) { - $arf .= '?username=' . $this->{_repository}->{user}; - if ( defined( $this->{_repository}->{pass} ) ) { - $arf .= ';password=' . $this->{_repository}->{pass}; + $this->repository->{pub} . $this->pkgname . '/' . $this->pkgname . $ext; + if ( defined( $this->repository->{user} ) ) { + $arf .= '?username=' . $this->repository->{user}; + if ( defined( $this->repository->{pass} ) ) { + $arf .= ';password=' . $this->repository->{pass}; } } my $ar; diff --git a/core/lib/Foswiki/Configure/Pluggable.pm b/core/lib/Foswiki/Configure/Pluggable.pm index 6ca6c719c3..689ee7fb72 100644 --- a/core/lib/Foswiki/Configure/Pluggable.pm +++ b/core/lib/Foswiki/Configure/Pluggable.pm @@ -50,6 +50,7 @@ use strict; use warnings; use Assert; +use Try::Tiny; =begin TML @@ -67,8 +68,15 @@ sub load { my $name = shift; my $modelName = 'Foswiki::Configure::Pluggables::' . $name; - eval("require $modelName; ${modelName}::construct(\@_);"); - die $@ if $@; + try { + Foswiki::load_package( $modelName, method => 'construct' ); + no strict 'refs'; + &{"${modelName}::construct"}(@_); + use strict 'refs'; + } + catch { + Foswiki::Exception::Fatal->rethrow($_); + }; } 1; diff --git a/core/lib/Foswiki/Configure/Pluggables/FINDEXTENSIONS.pm b/core/lib/Foswiki/Configure/Pluggables/FINDEXTENSIONS.pm index 0c8106e018..54f6dbc178 100644 --- a/core/lib/Foswiki/Configure/Pluggables/FINDEXTENSIONS.pm +++ b/core/lib/Foswiki/Configure/Pluggables/FINDEXTENSIONS.pm @@ -14,8 +14,6 @@ use strict; use warnings; use Assert; -use Foswiki::Configure::Pluggable (); -our @ISA = ('Foswiki::Configure::Pluggable'); sub construct { my ( $class, $settings, $file, $line ) = @_; diff --git a/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm b/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm index 11157b6ddf..cdb79aff25 100755 --- a/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm +++ b/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm @@ -30,7 +30,7 @@ sub construct { $Foswiki::cfg{LocalesDir} || Foswiki::Configure::FileUtil::findFileOnPath('../locale') || ''; - Foswiki::Configure::Load::expandValue($d); + $Foswiki::app->cfg->expandValue($d); opendir( DIR, $d ) or die "Failed to open LocalesDir $Foswiki::cfg{LocalesDir}"; @@ -66,7 +66,7 @@ sub construct { } my $value = Foswiki::Configure::Value->new( - 'BOOLEAN', + typename => 'BOOLEAN', LABEL => $label, keys => '{Languages}{' . $keys . '}{Enabled}', default => 0, diff --git a/core/lib/Foswiki/Configure/Pluggables/PLUGINS.pm b/core/lib/Foswiki/Configure/Pluggables/PLUGINS.pm index 8658e81bb1..2ab0bb7655 100755 --- a/core/lib/Foswiki/Configure/Pluggables/PLUGINS.pm +++ b/core/lib/Foswiki/Configure/Pluggables/PLUGINS.pm @@ -59,20 +59,20 @@ sub construct { push( @$settings, Foswiki::Configure::Value->new( - 'BOOLEAN', - LABEL => $plugin, - keys => "{Plugins}{$plugin}{Enabled}", - default => '0', # Not enabled - EXPERT => $expert{$plugin} + typename => 'BOOLEAN', + LABEL => $plugin, + keys => "{Plugins}{$plugin}{Enabled}", + default => '0', # Not enabled + EXPERT => $expert{$plugin} ) ); push( @$settings, Foswiki::Configure::Value->new( - 'STRING', - CHECKER => 'PLUGIN_MODULE', - LABEL => "$plugin Module", - keys => "{Plugins}{$plugin}{Module}", + typename => 'STRING', + CHECKER => 'PLUGIN_MODULE', + LABEL => "$plugin Module", + keys => "{Plugins}{$plugin}{Module}", # Note: as tempting as it may seem, DO NOT set # undefok. Otherwise hints will be invisible. diff --git a/core/lib/Foswiki/Configure/Pluggables/SCRIPTHASH.pm b/core/lib/Foswiki/Configure/Pluggables/SCRIPTHASH.pm index d988f1ed0a..f22d395048 100644 --- a/core/lib/Foswiki/Configure/Pluggables/SCRIPTHASH.pm +++ b/core/lib/Foswiki/Configure/Pluggables/SCRIPTHASH.pm @@ -92,10 +92,10 @@ sub construct { # Create the item under the current heading my $value = Foswiki::Configure::Value->new( - 'URLPATH', - keys => $keys, - desc => "Full URL for $script script. Rarely modified.", - EXPERT => 1, + typename => 'URLPATH', + keys => $keys, + desc => "Full URL for $script script. Rarely modified.", + EXPERT => 1, # By providing a default we are suggesting it is a # good idea - which it isn't. So don't. diff --git a/core/lib/Foswiki/Configure/Reporter.pm b/core/lib/Foswiki/Configure/Reporter.pm index 048270242b..f73577940a 100644 --- a/core/lib/Foswiki/Configure/Reporter.pm +++ b/core/lib/Foswiki/Configure/Reporter.pm @@ -1,14 +1,16 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Reporter; - -use strict; -use warnings; +use v5.14; use Assert; use JSON (); use Data::Dumper (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + # Number of levels of a stack trace to keep use constant KEEP_STACK_LEVELS => 0; #( (DEBUG) ? 2 : 0 ); @@ -47,19 +49,46 @@ ERROR message. =cut -sub new { - my ($class) = @_; +=begin TML - my $this = bless( - { - messages => [], - changes => {}, - hints => {} - }, - $class - ); - $this->clear(); - return $this; +---++ ObjectAttribute messages -> \@messages + +Get the content of the reporter. @messages is an ordered array of hashes, +each of which has fields: + * level: one of errors, warnings, notes + * text: text of the message +Each message corresponds to a single parameter to one of the ERROR, +WARN or NOTES methods. + +=cut + +=begin TML + +---++ ObjectAttribute changes -> \%changes + +Get the content of the reporter. %changes is a hash mapping a key +to a (new) value. Each entry corresponds to a call to the CHANGED +method (though multiple calls to CHANGED with the same keys will +only result in one entry). + +=cut + +=begin TML + +---++ ObjectAttribute hints -> \%hints + +Get the content of the hints hash. Flags are used to supply hints to the +UI as to how errors may be resolved. + +=cut + +has messages => ( is => 'rw', lazy => 1, clearer => 1, default => sub { [] }, ); +has changes => ( is => 'rw', lazy => 1, clearer => 1, default => sub { {} }, ); +has hints => ( is => 'rw', lazy => 1, clearer => 1, default => sub { {} }, ); + +sub BUILD { + my $this = shift; + $this->clear; } =begin TML @@ -73,7 +102,7 @@ message. Returns the reporter to allow chaining. sub NOTE { my $this = shift; - push( @{ $this->{messages} }, map { { level => 'notes', text => $_ } } @_ ); + push( @{ $this->messages }, map { { level => 'notes', text => $_ } } @_ ); return $this; } @@ -88,10 +117,8 @@ message. Returns the reporter to allow chaining. sub WARN { my $this = shift; - push( - @{ $this->{messages} }, - map { { level => 'warnings', text => $_ } } @_ - ); + push( @{ $this->messages }, + map { { level => 'warnings', text => $_ } } @_ ); } =begin TML @@ -105,8 +132,7 @@ message. Returns the reporter to allow chaining. sub ERROR { my $this = shift; - push( @{ $this->{messages} }, - map { { level => 'errors', text => $_ } } @_ ); + push( @{ $this->messages }, map { { level => 'errors', text => $_ } } @_ ); return $this; } @@ -126,7 +152,7 @@ Returns the reporter to allow chaining. sub CHANGED { my ( $this, $keys ) = @_; - $this->{changes}->{$keys} = uneval( eval("\$Foswiki::cfg$keys") ); + $this->changes->{$keys} = uneval( eval("\$Foswiki::cfg$keys") ); return $this; } @@ -162,7 +188,7 @@ $level is one of notes, warnings or errors. sub has_level { my ( $this, $level ) = @_; - foreach my $m ( @{ $this->{messages} } ) { + foreach my $m ( @{ $this->messages } ) { return 1 if ( $m->{level} eq $level ); } return 0; @@ -188,9 +214,9 @@ If =$value= is given, the previous value is returned. sub hint { my ( $this, $hint, $value ) = @_; - my $curval = $this->{$hint}; + my $curval = $this->hints->{$hint}; if ( defined $value ) { - $this->{hints}{$hint} = $value; + $this->hints->{$hint} = $value; } return $curval; } @@ -206,61 +232,9 @@ Returns the reporter to allow chaining. sub clear { my $this = shift; - $this->{messages} = []; - $this->{changes} = {}; - $this->{hints} = {}; - return $this; -} - -=begin TML - ----++ ObjectMethod messages() -> \@messages - -Get the content of the reporter. @messages is an ordered array of hashes, -each of which has fields: - * level: one of errors, warnings, notes - * text: text of the message -Each message corresponds to a single parameter to one of the ERROR, -WARN or NOTES methods. - -=cut - -sub messages { - my ($this) = @_; - - return $this->{messages}; -} - -=begin TML - ----++ ObjectMethod changes() -> \%changes - -Get the content of the reporter. %changes is a hash mapping a key -to a (new) value. Each entry corresponds to a call to the CHANGED -method (though multiple calls to CHANGED with the same keys will -only result in one entry). - -=cut - -sub changes { - my ($this) = @_; - - return $this->{changes}; -} - -=begin TML - ----++ ObjectMethod hints() -> \%hints - -Get the content of the hints hash. Flags are used to supply hints to the -UI as to how errors may be resolved. - -=cut - -sub hints { - my ($this) = @_; - - return $this->{hints}; + $this->clear_messages; + $this->clear_changes; + $this->clear_hints; } =begin TML @@ -300,7 +274,7 @@ sub stringify { ) . $_->{text} } - grep { $all_levels || $l{ $_->{level} } } @{ $this->messages() } + grep { $all_levels || $l{ $_->{level} } } @{ $this->messages } ); if ( $all_levels || $l{changes} ) { @@ -309,11 +283,11 @@ sub stringify { map { ( $many_levels ? 'CHANGE: ' : '' ) . "$_ = " . ( - defined $this->changes()->{$_} - ? $this->changes()->{$_} + defined $this->changes->{$_} + ? $this->changes->{$_} : 'undef' ) - } keys %{ $this->changes() } + } keys %{ $this->changes } ); } return '' unless scalar(@report); diff --git a/core/lib/Foswiki/Configure/Root.pm b/core/lib/Foswiki/Configure/Root.pm index 1e5e0f3377..38cecb4c44 100644 --- a/core/lib/Foswiki/Configure/Root.pm +++ b/core/lib/Foswiki/Configure/Root.pm @@ -8,17 +8,17 @@ The root of the configuration item tree. =cut package Foswiki::Configure::Root; +use v5.14; -use strict; -use warnings; +use Moo; +extends qw(Foswiki::Configure::Section); -use Foswiki::Configure::Section (); -our @ISA = ('Foswiki::Configure::Section'); +around BUILDARGS => sub { + my $orig = shift; + my $class = shift; -sub new { - my ($class) = @_; - return $class->SUPER::new( headline => '' ); -} + return $orig->( $class, @_, headline => '' ); +}; 1; __END__ diff --git a/core/lib/Foswiki/Configure/Wizard.pm b/core/lib/Foswiki/Configure/Wizard.pm index 1975a7524b..a5204c34ac 100644 --- a/core/lib/Foswiki/Configure/Wizard.pm +++ b/core/lib/Foswiki/Configure/Wizard.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizard; +use v5.14; =begin TML @@ -32,11 +33,19 @@ See the documentation for the UI for more information. =cut -use strict; -use warnings; - use Assert; +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + +has param_source => ( + is => 'rw', + lazy => 1, + default => sub { {} }, + isa => Foswiki::Object::isaHASH('param_source'), +); + =begin TML ---++ StaticMethod loadWizard($name, $param_source) -> $wizard @@ -54,15 +63,19 @@ sub loadWizard { my $class = 'Foswiki::Configure::Wizards::' . $name; - eval("require $class"); - die "Failed to load wizard $class: $@" if $@; + my $wizardObj; - return $class->new($param_source); -} + try { + Foswiki::load_class($class); + $wizardObj = $class->new( param_source => $param_source ); + } + catch { + Foswiki::Exception::Fatal->throw( + text => "Failed to load wizard $class: " + . Foswiki::Exception::errorStr($_) ); + }; -sub new { - my ( $class, $ps ) = @_; - return bless( { param_source => $ps }, $class ); + return $wizardObj; } =begin TML @@ -75,7 +88,7 @@ Returns the value of a parameter that was given when the wizard was invoked. sub param { my ( $this, $param ) = @_; - return $this->{param_source}->{$param}; + return $this->param_source->{$param}; } 1; diff --git a/core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm b/core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm index 7a86d0d46f..9332a4a702 100644 --- a/core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm +++ b/core/lib/Foswiki/Configure/Wizards/AutoConfigureEmail.pm @@ -1,24 +1,23 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::AutoConfigureEmail; +use v5.14; =begin TML ----++ package Foswiki::Configure::Wizards::AutoConfigureEmail +---++ Class Foswiki::Configure::Wizards::AutoConfigureEmail Wizard to try to autoconfigure email. =cut -use strict; -use warnings; +use Foswiki::IP qw/$IPv6Avail :regexp :info/; -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); use constant DEBUG_SSL => 1; -use Foswiki::IP qw/$IPv6Avail :regexp :info/; - # N.B. Below the block comment are not enabled placeholders # Search order (specify hash key). Agents with custom sniffers # ( code => keys ) should be tried first. @@ -103,8 +102,8 @@ sub autoconfigure { '$Foswiki::cfg{DataDir}/SmimePrivateKey.pem', ); } - Foswiki::Configure::Load::expandValue($certFile); - Foswiki::Configure::Load::expandValue($keyFile); + $Foswiki::app->cfg->expandValue($certFile); + $Foswiki::app->cfg->expandValue($keyFile); unless ( $certFile && $keyFile && -r $certFile && -r $keyFile ) { $reporter->ERROR( < ( is => 'rw', lazy => 1, default => sub { {} }, predicate => 1, ); +has errors => ( is => 'rw', lazy => 1, default => sub { [] }, ); + # Convert a date in the formats dd mm yyyy or dd Mmm yyyy to a unique integer sub d2n { my ( $d, $m, $y ) = @_; @@ -67,10 +69,7 @@ sub _getListOfExtensions { ( $Foswiki::RELEASE, $Foswiki::VERSION, $Foswiki::Plugins::VERSION ); my @consulted = (); - return ( $this->{list} ) if $this->{list}; - - $this->{list} = {}; - $this->{errors} = []; + return ( $this->list ) if $this->has_list; foreach my $place ( findRepositories() ) { next unless defined $place->{data}; @@ -125,7 +124,7 @@ MESS $errorMsg .= " you probably need to add the optional =,username,password)= options to the repository definition"; } - push( @{ $this->{errors} }, $errorMsg ); + push( @{ $this->errors }, $errorMsg ); } else { @@ -149,14 +148,14 @@ MESS } else { push( - @{ $this->{errors} }, + @{ $this->errors }, "Error accessing $place->{name}: no content" ); } } else { push( - @{ $this->{errors} }, + @{ $this->errors }, "Error accessing $place->{name}: " . $response->message() ); @@ -164,14 +163,14 @@ MESS eval('require LWP'); if ($@) { push( - @{ $this->{errors} }, + @{ $this->errors }, "This may be because the CPAN 'LWP' module isn't installed." ); } } } - return ( $this->{list}, @consulted ); + return ( $this->list, @consulted ); } sub _studyRow { @@ -205,7 +204,7 @@ sub _studyRow { } } - $this->{list}->{ $dep->{name} } = $dep; + $this->list->{ $dep->{name} } = $dep; return ''; } @@ -262,7 +261,7 @@ sub _get_extensions { $reporter->NOTE( "> Looked in " . join( ' ', @consultedLocations ) ); - $reporter->ERROR( @{ $this->{errors} } ) if scalar( @{ $this->{errors} } ); + $reporter->ERROR( @{ $this->errors } ) if scalar( @{ $this->errors } ); if ( $set eq 'Installed' ) { $reporter->NOTE("> *Found $installedCount Installed extensions* "); diff --git a/core/lib/Foswiki/Configure/Wizards/InstallExtensions.pm b/core/lib/Foswiki/Configure/Wizards/InstallExtensions.pm index f45175ed22..a5202c370d 100755 --- a/core/lib/Foswiki/Configure/Wizards/InstallExtensions.pm +++ b/core/lib/Foswiki/Configure/Wizards/InstallExtensions.pm @@ -1,8 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::InstallExtensions; - -use strict; -use warnings; +use v5.14; use File::Copy (); use File::Spec (); @@ -12,19 +10,20 @@ use Assert; =begin TML ----+ package Foswiki::Configure::Wizards:InstallExtensions +---+ Class Foswiki::Configure::Wizards:InstallExtensions Install and remove extensions =cut -require Foswiki::Configure::Wizard; -our @ISA = ('Foswiki::Configure::Wizard'); - use Foswiki::Configure::Package (); use Foswiki::Configure::Dependency (); use Foswiki::Configure::Wizards::ExploreExtensions (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); + my %validArgs = ( USELOCAL => 1, EXPANDED => 1, diff --git a/core/lib/Foswiki/Configure/Wizards/Plugins.pm b/core/lib/Foswiki/Configure/Wizards/Plugins.pm index 24f629a8e0..706c7a02c0 100644 --- a/core/lib/Foswiki/Configure/Wizards/Plugins.pm +++ b/core/lib/Foswiki/Configure/Wizards/Plugins.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::Plugins; +use v5.14; =begin TML @@ -9,16 +10,14 @@ Wizard to verify script paths. =cut -use strict; -use warnings; - use Assert; use Foswiki; use Foswiki::Configure::Load (); -require Foswiki::Configure::Wizard; -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); =begin TML @@ -192,11 +191,11 @@ sub _setEnable { # Add it to the $spec $spec->addChild( Foswiki::Configure::Value->new( - 'BOOLEAN', - LABEL => $plu, - keys => "${clef}{Enabled}", - CHECKER => 'PLUGIN_MODULE', - default => '0' + typename => 'BOOLEAN', + LABEL => $plu, + keys => "${clef}{Enabled}", + CHECKER => 'PLUGIN_MODULE', + default => '0' ) ); } @@ -221,11 +220,11 @@ sub _setModule { # Add it to the $spec $spec->addChild( Foswiki::Configure::Value->new( - 'STRING', - LABEL => "$plu Module", - keys => "{Plugins}{$plu}{Module}", - CHECKER => 'PLUGIN_MODULE', - default => 'Foswiki::Plugins::$plu' + typename => 'STRING', + LABEL => "$plu Module", + keys => "{Plugins}{$plu}{Module}", + CHECKER => 'PLUGIN_MODULE', + default => 'Foswiki::Plugins::$plu' ) ); } diff --git a/core/lib/Foswiki/Configure/Wizards/SMIMECertificate.pm b/core/lib/Foswiki/Configure/Wizards/SMIMECertificate.pm index c4b737d41a..71ae7eaba1 100644 --- a/core/lib/Foswiki/Configure/Wizards/SMIMECertificate.pm +++ b/core/lib/Foswiki/Configure/Wizards/SMIMECertificate.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::SMIMECertificate; +use v5.14; =begin TML @@ -9,11 +10,8 @@ Wizard methods to handle SMIME certificates. =cut -use strict; -use warnings; - -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +extends qw(Foswiki::Configure::Wizard); =begin TML @@ -34,9 +32,9 @@ sub generate_cert { $checks ||= { '.selfSigned' => 1 }; my $certfile = '$Foswiki::cfg{DataDir}' . "/SmimeCertificate.pem"; - Foswiki::Configure::Load::expandValue($certfile); + $Foswiki::app->cfg->expandValue($certfile); my $keyfile = '$Foswiki::cfg{DataDir}' . "/SmimePrivateKey.pem"; - Foswiki::Configure::Load::expandValue($keyfile); + $Foswiki::app->cfg->expandValue($keyfile); my $ok = 1; unless ( $Foswiki::cfg{WebMasterEmail} ) { @@ -296,9 +294,9 @@ sub cancel_cert { my $ok = 1; my $certfile = '$Foswiki::cfg{DataDir}' . "/SmimeCertificate.pem"; - Foswiki::Configure::Load::expandValue($certfile); + $Foswiki::app->cfg->expandValue($certfile); my $keyfile = '$Foswiki::cfg{DataDir}' . "/SmimePrivateKey.pem"; - Foswiki::Configure::Load::expandValue($keyfile); + $Foswiki::app->cfg->expandValue($keyfile); if ( -f "$certfile.csr" || -f "$keyfile.csr" ) { if ( -f "$certfile.csr" && !unlink("$certfile.csr") ) { @@ -334,7 +332,7 @@ sub show_request { my ( $this, $reporter ) = @_; my $certfile = '$Foswiki::cfg{DataDir}' . "/SmimeCertificate.pem"; - Foswiki::Configure::Load::expandValue($certfile); + $Foswiki::app->cfg->expandValue($certfile); my $csrfile = "$certfile.csr"; unless ( -r $csrfile ) { diff --git a/core/lib/Foswiki/Configure/Wizards/SSLCertificates.pm b/core/lib/Foswiki/Configure/Wizards/SSLCertificates.pm index 121c76ab18..dc5406f4fb 100644 --- a/core/lib/Foswiki/Configure/Wizards/SSLCertificates.pm +++ b/core/lib/Foswiki/Configure/Wizards/SSLCertificates.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::SSLCertificates; +use v5.14; =begin TML @@ -9,13 +10,11 @@ Wizard to check SSL certificates. =cut -use strict; -use warnings; - use Foswiki::Configure::Checker (); -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); =begin TML @@ -252,7 +251,7 @@ sub show_active { my ( $this, $reporter ) = @_; my $certfile = '$Foswiki::cfg{DataDir}' . "/SmimeCertificate.pem"; - Foswiki::Configure::Load::expandValue($certfile); + $Foswiki::app->cfg->expandValue($certfile); unless ( -r $certfile ) { return $this->ERROR("No Certificate is installed"); @@ -308,9 +307,9 @@ sub install_cert { my ( $this, $reporter ) = @_; my $certfile = '$Foswiki::cfg{DataDir}' . "/SmimeCertificate.pem"; - Foswiki::Configure::Load::expandValue($certfile); + $Foswiki::app->cfg->expandValue($certfile); my $keyfile = '$Foswiki::cfg{DataDir}' . "/SmimePrivateKey.pem"; - Foswiki::Configure::Load::expandValue($keyfile); + $Foswiki::app->cfg->expandValue($keyfile); unless ( -r "$certfile.csr" && -r "$keyfile.csr" ) { $reporter->ERROR("No pending Certificate request"); diff --git a/core/lib/Foswiki/Configure/Wizards/Save.pm b/core/lib/Foswiki/Configure/Wizards/Save.pm index 5c123a6c05..ea1433a744 100644 --- a/core/lib/Foswiki/Configure/Wizards/Save.pm +++ b/core/lib/Foswiki/Configure/Wizards/Save.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::Save; +use v5.14; =begin TML @@ -10,9 +11,6 @@ taking a backup as necessary. =cut -use strict; -use warnings; - use Assert; use Errno; @@ -23,8 +21,9 @@ use Foswiki::Configure::LoadSpec (); use Foswiki::Configure::Checker (); use Foswiki::Configure::FileUtil (); -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); use constant TRACE_SAVE => 0; @@ -116,7 +115,8 @@ sub _backupCurrentContent { chown $uid, $gid, $backup; } else { - die "Unable to open $path.$n for write: $!\n"; + Foswiki::Exception::Fatal->throw( + text => "Unable to open $path.$n for write: $!\n" ); } umask($um); @@ -141,8 +141,8 @@ sub save { my $isBootstrap = $Foswiki::cfg{isBOOTSTRAPPING}; my $logger; - if ($Foswiki::Plugins::SESSION) { - $logger = $Foswiki::Plugins::SESSION->logger; + if ($Foswiki::app) { + $logger = $Foswiki::app->logger; } elsif ( defined $this->param('logger') ) { $logger = $this->param('logger'); @@ -181,7 +181,8 @@ sub save { eval($1); } if ($@) { - print STDERR "Error reading existing $lsc: $@"; + print STDERR "Error reading existing $lsc: ", + Foswiki::Exception::errorStr($@); # Continue, but will be unable to detect changes } @@ -247,11 +248,11 @@ sub save { if ( $this->param('set') ) { while ( my ( $k, $v ) = each %{ $this->param('set') } ) { my $spec = $root->getValueObject($k); - eval("\$spec->{old_value} = \$Foswiki::cfg$k") if $spec; + eval("\$spec->attrs->{old_value} = \$Foswiki::cfg$k") if $spec; if ( $spec && defined $v && !ref($v) ) { $v =~ m/^(.*)$/s; - $v = $1; # untaint - $spec->{saving_value} = $v; + $v = $1; # untaint + $spec->attrs->{saving_value} = $v; eval { $v = $spec->decodeValue($v); }; if ($@) { $reporter->ERROR( @@ -270,11 +271,11 @@ sub save { eval("\$Foswiki::cfg$k=\$v"); } elsif ($spec->CHECK_option('undefok') - || $spec->{typename} eq 'BOOLEAN' ) + || $spec->attrs->{typename} eq 'BOOLEAN' ) { print STDERR "CLEARING $k\n" if TRACE_SAVE; eval("undef \$Foswiki::cfg$k"); - $spec->{saving_value} = undef; + $spec->attrs->{saving_value} = undef; } else { $reporter->ERROR( @@ -295,11 +296,11 @@ sub save { # when a configuration value is saved. It can modify the value # being saved, such as to hash a password, but never modify other # values. - if ( $spec && $spec->{ONSAVE} ) { + if ( $spec && $spec->attrs->{ONSAVE} ) { my $checker = Foswiki::Configure::Checker::loadChecker($spec); if ( $checker && $checker->can('onSave') ) { eval( -"\$checker->onSave( \$reporter, \$k, \$Foswiki::cfg$k, \$spec->{old_value} )" +"\$checker->onSave( \$reporter, \$k, \$Foswiki::cfg$k, \$spec->attrs->{old_value} )" ); } } diff --git a/core/lib/Foswiki/Configure/Wizards/ScriptHash.pm b/core/lib/Foswiki/Configure/Wizards/ScriptHash.pm index 58b8e6e589..3f79d301ae 100644 --- a/core/lib/Foswiki/Configure/Wizards/ScriptHash.pm +++ b/core/lib/Foswiki/Configure/Wizards/ScriptHash.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::ScriptHash; +use v5.14; =begin TML @@ -9,9 +10,6 @@ Wizard to verify script paths. =cut -use strict; -use warnings; - use Assert; use JSON (); @@ -19,8 +17,9 @@ use JSON (); use Foswiki::Configure::Dependency (); use Foswiki::Configure::Load (); -require Foswiki::Configure::Wizard; -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Configure::Wizard); =begin TML diff --git a/core/lib/Foswiki/Configure/Wizards/SendTestEmail.pm b/core/lib/Foswiki/Configure/Wizards/SendTestEmail.pm index ea7f6c3f2c..935f136aa0 100644 --- a/core/lib/Foswiki/Configure/Wizards/SendTestEmail.pm +++ b/core/lib/Foswiki/Configure/Wizards/SendTestEmail.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::SendTestEmail; +use v5.14; =begin TML @@ -9,11 +10,8 @@ Wizard to test email. =cut -use strict; -use warnings; - -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Moo; +extends qw(Foswiki::Configure::Wizard); # Use to disable stream redirection during $net->sendEmail. This is # required because Foswiki::Net doesn't use the Foswiki::Sandbox :-( @@ -36,10 +34,10 @@ sub send { # Expand a couple of required config settings for # Foswiki::Net::sendEmail after making sure we can restore them. - Foswiki::Configure::Load::expandValue( + $Foswiki::app->cfg->expandValue( $Foswiki::cfg{Email}{SmimeCertificateFile} ); - Foswiki::Configure::Load::expandValue( $Foswiki::cfg{Email}{SmimeKeyFile} ); + $Foswiki::app->cfg->expandValue( $Foswiki::cfg{Email}{SmimeKeyFile} ); if ( $Foswiki::cfg{Engine} && $Foswiki::cfg{Engine} =~ m/FastCGI/ ) { $noredirect = 1; # FCGI doesn't allow redirection of STDERR diff --git a/core/lib/Foswiki/Configure/Wizards/StudyWebserver.pm b/core/lib/Foswiki/Configure/Wizards/StudyWebserver.pm index edba98fbf1..e1da67fdd5 100644 --- a/core/lib/Foswiki/Configure/Wizards/StudyWebserver.pm +++ b/core/lib/Foswiki/Configure/Wizards/StudyWebserver.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Configure::Wizards::StudyWebserver; +use v5.14; =begin TML @@ -7,19 +8,17 @@ package Foswiki::Configure::Wizards::StudyWebserver; =cut -use strict; -use warnings; - use CGI (); use FindBin (); use File::Spec (); use JSON (); - -use Foswiki::Configure::Wizard (); -our @ISA = ('Foswiki::Configure::Wizard'); +use Try::Tiny; use Foswiki::Net (); +use Moo; +extends qw(Foswiki::Configure::Wizard); + our $inc_rubric = '@INC library path _This is the Perl library path, used to load Foswiki modules, third-party modules used by some plugins, and Perl built-in modules_ '; @@ -36,6 +35,8 @@ sub report { $reporter->NOTE('---+ Environment Variables'); + my $env = $Foswiki::app->env; + # Check the execution environment my $XENV = $this->_getScriptENV($reporter); @@ -43,10 +44,10 @@ sub report { my $uid = getlogin() || getpwuid($>); my @groups; - eval { + try { @groups = map { lc( getgrgid($_) ) } split( ' ', $( ); - }; - if ($@) { + } + catch { # Try to use Cygwin's 'id' command - may be on the path, # since Cygwin is probably installed to supply ls, egrep, @@ -64,8 +65,8 @@ sub report { "Unable to query execution environment. The following analysis only reflects the configure environment." ); $reporter->NOTE('| *Variable* | *Configure* |'); - for my $key ( sort keys %ENV ) { - my $value = $ENV{$key}; + for my $key ( sort keys %{$env} ) { + my $value = $env->{$key}; my $decoded = ''; if ( $key eq 'HTTP_COOKIE' && $value ) { @@ -190,14 +191,14 @@ HERE # in current distributions. $Foswiki::cfg{DETECTED}{ModPerlLoaded} = - ( exists $ENV{SERVER_SOFTWARE} - && ( $ENV{SERVER_SOFTWARE} =~ m/mod_perl/ ) ) + ( exists $env->{SERVER_SOFTWARE} + && ( $env->{SERVER_SOFTWARE} =~ m/mod_perl/ ) ) || ( exists $XENV->{ENV}->{SERVER_SOFTWARE} && ( $XENV->{ENV}->{SERVER_SOFTWARE} =~ m/mod_perl/ ) ); # Detect whether we are actually running under mod_perl # - test for MOD_PERL alone, which is enough. - $Foswiki::cfg{DETECTED}{UsingModPerl} = exists $ENV{MOD_PERL}; + $Foswiki::cfg{DETECTED}{UsingModPerl} = exists $env->{MOD_PERL}; $Foswiki::cfg{DETECTED}{ModPerlVersion} = eval('use mod_perl2; return $mod_perl2::VERSION'); @@ -381,13 +382,15 @@ sub _compareHashes { sub _getScriptENV { my ( $this, $reporter ) = @_; + my $env = $Foswiki::app->env; + my @pars = ( -name => 'FOSWIKI_CONFIGURATION', -value => time, -path => '/', -expires => "+1h" ); - push @pars, -secure => 1 if ( $ENV{HTTPS} && $ENV{HTTPS} eq 'on' ); + push @pars, -secure => 1 if ( $env->{HTTPS} && $env->{HTTPS} eq 'on' ); my $cookie = CGI->cookie(@pars); local $Foswiki::VERSION = "CONFIGURATION"; my $net = Foswiki::Net->new; @@ -471,7 +474,7 @@ sub _getScriptENV { } sub _getBinDir { - my $dir = $ENV{SCRIPT_FILENAME} || '.'; + my $dir = $Foswiki::app->env->{SCRIPT_FILENAME} || '.'; $dir =~ s(/+configure[^/]*$)(); return $dir; }