Skip to content

Commit

Permalink
Item12180: Simplify 16326.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16327 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Jan 2, 2013
1 parent 326d4e0 commit 73199d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
24 changes: 7 additions & 17 deletions core/lib/Foswiki/Configure/FoswikiCfg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -814,25 +814,15 @@ sub startVisit {
}

if ( defined $value ) {

# For some reason Data::Dumper ignores the second parameter sometimes
# when -T is enabled, so have to do a substitution
my ( $txt, $require );
my $type = $visitee->getType;
if ( $type && $type->can('value2string') ) {
( $txt, $require ) = $type->value2string( $keys, $value );
if ( defined $require ) {
if ( ref $require ) {
$this->{requires}{$_} = 1 foreach (@$require);
}
else {
$this->{requires}{$require} = 1;
}
my ( $txt, $require ) = $type->value2string( $keys, $value );
if ( defined $require ) {
if ( ref $require ) {
$this->{requires}{$_} = 1 foreach (@$require);
}
else {
$this->{requires}{$require} = 1;
}
}
else {
$txt = Data::Dumper->Dump( [$value] );
$txt =~ s/VAR1/Foswiki::cfg$keys/;
}

# Substitute any existing value, or append if not there
Expand Down
32 changes: 32 additions & 0 deletions core/lib/Foswiki/Configure/Type.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ sub string2value {
return $val;
}

=begin TML
---++ ObjectMethod value2string($value) -> ($string, $require)
Used to encode output values during save. The default is
adequate for most value types, but this hook allows for special
encoding when needed. See PASSWORD for an example.
$value - the value to be encoded (should not be undef; that's
filtered earlier.
$require - the name of a require module that's required for decoding
the value. (LSC will contain require $require;)
Can be an arrayref [qw/mod1 mod2/]. undef is acceptable.
This is mechanism is intended for exceptional cases. This default
method should be adequate for virtually every item type.
=cut

sub value2string {
my $this = shift;
my ( $keys, $value ) = @_;

# For some reason Data::Dumper ignores the second parameter sometimes
# when -T is enabled, so have to do a substitution

my $txt = Data::Dumper->Dump( [$value] );
$txt =~ s/VAR1/Foswiki::cfg$keys/;

return $txt;
}

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

0 comments on commit 73199d3

Please sign in to comment.