Skip to content

Commit

Permalink
Item12952: various bugs highlighted during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford committed Aug 29, 2014
1 parent fac88d8 commit 6afdb9a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 30 deletions.
3 changes: 2 additions & 1 deletion core/lib/Foswiki/Configure/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use File::Spec ();

use Assert;

use Foswiki::Configure::Load ();
use Foswiki::Configure::Load ();
use Foswiki::Configure::Dependency ();

use constant GUESSED_MESSAGE => <<'HERE';
I had to guess this setting in order to continue checking. You must
Expand Down
30 changes: 16 additions & 14 deletions core/lib/Foswiki/Configure/Checkers/PLUGIN_MODULE.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ our @ISA = ('Foswiki::Configure::Checker');
use Assert;

sub check_current_value {
my ($this, $reporter) = @_;
my ( $this, $reporter ) = @_;

my $keys = $this->{item}->{keys};

# NOTE: this checker is also invoked from the PLUGIN_ENABLED
# checker, hence the /{Enabled}$/
$keys =~ /^{Plugins}{(.*)}{(Module|Enabled)}$/;
ASSERT($1) if DEBUG;
my $plug = $1;
my $mod = $Foswiki::cfg{Plugins}{$plug}{Module};
my $mod = $Foswiki::cfg{Plugins}{$plug}{Module};

unless ($mod) {
$reporter->WARN("$plug has no {Plugins}{$plug}{Module}");
Expand All @@ -36,30 +37,31 @@ sub check_current_value {

my $altmod = ( $enabled eq 'Foswiki' ) ? 'TWiki' : 'Foswiki';

my @found;
my %found;

foreach my $dir ( @INC ) {
foreach my $dir (@INC) {
if ( -e "$dir/$enabled/$plugpath.pm" ) {
push(@found, "$dir/$enabled/$plugpath.pm");
$found{"$dir/$enabled/$plugpath.pm"} = 1;
}
if ( -e "$dir/$altmod/$plugpath.pm" ) {
push(@found, "$dir/$altmod/$plugpath.pm" );
$found{"$dir/$altmod/$plugpath.pm"} = 1;
}
}
if ( !scalar(@found) ) {
if ( !scalar( keys %found ) ) {
$reporter->ERROR(
"$mod is enabled in LocalSite.cfg but was not found in the \@INC path"
) ;
"$mod is enabled in LocalSite.cfg but was not found in the \@INC path"
);
}
elsif ( scalar(@found) > 1 ) {
elsif ( scalar( keys %found ) > 1 ) {
if ( $enabled eq 'TWiki' ) {
$reporter->WARN(
"$mod module is enabled - be sure this is what you want. Multiple versions are possibly installed."
"$mod module is enabled - be sure this is what you want. Multiple versions are possibly installed."
);
} else {
}
else {
$reporter->WARN(
"$mod found in multiple locations in the library path. Possible obsolete extensions should be removed. Duplicates: ".join(' ', @found)
);
"$mod found in multiple locations in the library path. Possible obsolete extensions should be removed. Duplicates: "
. join( ' ', keys %found ) );
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions core/lib/Foswiki/Configure/LoadSpec.pm
Original file line number Diff line number Diff line change
Expand Up @@ -423,21 +423,10 @@ sub _parse {
$open->{defined_at} = [@context];

# Record the value *string*, internal formatting et al.
# This is the best way to retain perl formatting while
# being sensitive to changes.
ASSERT( UNTAINTED($value), $value ) if DEBUG;
if ( $open->{typename} eq 'REGEX' ) {

# regexp; convert to string
$value = eval $value;
$value = "$value";
}
elsif ( $open->{typename} eq 'PERL' ) {

# PERL - convert to string
my $var1 = Data::Dumper->Dump( [$value] );
$var1 =~ s/^.*=\s*//;
$value = $var1;
}
$open->{default} = $value;
$open->{default} = $open->encodeValue( eval $value );

$open->{keys} = $keys;
unless ($isEnhancing) {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Section.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ sub getValueObject {

sub getAllValueKeys {
my $this = shift;
return keys $this->{_vobCache};
return keys %{ $this->{_vobCache} };
}

1;
Expand Down
59 changes: 59 additions & 0 deletions core/lib/Foswiki/Configure/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ package Foswiki::Configure::Value;

use strict;
use warnings;

use Data::Dumper ();

use Assert;

use Foswiki::Configure::Item ();
our @ISA = ('Foswiki::Configure::Item');

Expand Down Expand Up @@ -301,6 +304,62 @@ sub stringify {
return $value;
}

=begin TML
---++ ObjectMethod encodeValue($true_value) -> $encoded_value
Encode a "real" cfg value as a string (if necessary) for passing
to other tools, such as UIs, in a type-sensitive way.
=cut

sub encodeValue {
my ( $this, $value ) = @_;

# Empty string always interpreted as undef
return '' if ( !defined $value );

if ( $this->{typename} eq 'REGEX' ) {
return "$value";
}
elsif ( $this->{typename} eq 'PERL' ) {
my $var1 = Data::Dumper->Dump( [$value] );
$var1 =~ s/^.*=\s*//;
return $var1;
}
else {
# Otherwise it's a type the UI can handle
return $value;
}
}

=begin TML
---++ ObjectMethod decodeValue($encoded_value) -> $true_value
Decode a string that represents the value (e.g a serialsed perl structure)
and return the 'true' value by applying type rules
=cut

sub decodeValue {
my ( $this, $value ) = @_;

# Empty string always interpreted as undef
return undef if ( !defined $value || $value eq '' );
if ( $this->{typename} eq 'REGEX' ) {
return qr/$value/;
}
elsif ( $this->{typename} eq 'PERL' ) {
my $value = eval $value;
ASSERT( !$@, $@ ) if DEBUG;
return $value;
}

# String or number or boolean, just sling it back
return $value;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit 6afdb9a

Please sign in to comment.