Skip to content

Commit

Permalink
Item11349: Improve Foswiki::Address handling 'root'
Browse files Browse the repository at this point in the history
addresses

git-svn-id: http://svn.foswiki.org/trunk@13372 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Dec 11, 2011
1 parent fcdfff2 commit 3c3e222
Showing 1 changed file with 78 additions and 76 deletions.
154 changes: 78 additions & 76 deletions core/lib/Foswiki/Address.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1063,106 +1063,108 @@ The output of =stringify()= is understood by =parse()=, and vice versa.
sub stringify {
my ( $this, %opts ) = @_;

ASSERT( $this->{web} or ref( $this->{webpath} ) eq 'ARRAY' ) if DEBUG;
ASSERT( $this->isValid(), 'valid address' ) if DEBUG;

# If there's a valid address; and check that we haven't already computed
# the stringification before with the same opts
if (
$this->isValid()
and (
not $this->{stringified}
or ( $opts{webseparator}
and $opts{webseparator} ne $this->{stringifiedwebsep} )
or ( $opts{topicseparator}
and $opts{topicseparator} ne $this->{stringifiedtopicsep} )
)
not $this->{stringified}
or ( $opts{webseparator}
and $opts{webseparator} ne $this->{stringifiedwebsep} )
or ( $opts{topicseparator}
and $opts{topicseparator} ne $this->{stringifiedtopicsep} )
)
{
$this->{stringifiedwebsep} = $opts{webseparator}
|| '/';
$this->{stringifiedtopicsep} = $opts{topicseparator}
|| '.';
$this->{stringified} =
join( $this->{stringifiedwebsep}, @{ $this->{webpath} } );
if ( $this->{topic} ) {
$this->{stringified} .=
$this->{stringifiedtopicsep} . $this->{topic};
if ( $this->{tompath} ) {
ASSERT( ref( $this->{tompath} ) eq 'ARRAY'
and scalar( @{ $this->{tompath} } ) )
if DEBUG;
print STDERR 'tompath: ' . Dumper( $this->{tompath} )
if TRACEATTACH;
print STDERR 'attachment: ' . Dumper( $this->{attachment} )
if TRACEATTACH;
ASSERT(
$this->{tompath}->[0] ne 'attachment'
or not $this->{tompath}->[1]
or ( $this->{attachment}
and $this->{attachment} eq $this->{tompath}->[1] )
) if DEBUG;
if ( $this->{tompath}->[0] eq 'attachment'
and scalar( @{ $this->{tompath} } ) == 2 )
{
$this->{stringified} .= '/' . $this->{tompath}->[1];
if ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
}
}
else {
if ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
if ( $this->{webpath} ) {
$this->{stringified} =
join( $this->{stringifiedwebsep}, @{ $this->{webpath} } );
if ( $this->{topic} ) {
$this->{stringified} .=
$this->{stringifiedtopicsep} . $this->{topic};
if ( $this->{tompath} ) {
ASSERT( ref( $this->{tompath} ) eq 'ARRAY'
and scalar( @{ $this->{tompath} } ) )
if DEBUG;
print STDERR 'tompath: ' . Dumper( $this->{tompath} )
if TRACEATTACH;
print STDERR 'attachment: ' . Dumper( $this->{attachment} )
if TRACEATTACH;
ASSERT(
$this->{tompath}->[0] ne 'attachment'
or not $this->{tompath}->[1]
or ( $this->{attachment}
and $this->{attachment} eq $this->{tompath}->[1] )
) if DEBUG;
if ( $this->{tompath}->[0] eq 'attachment'
and scalar( @{ $this->{tompath} } ) == 2 )
{
$this->{stringified} .= '/' . $this->{tompath}->[1];
if ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
}
}
$this->{stringified} = '\''
. $this->{stringified} . '\'/'
. $this->{tompath}->[0];
if ( $this->{tompath}->[1] ) {
my @path = @{ $this->{tompath} };
my $root = shift(@path);

if ( $root eq 'META' and scalar(@path) ) {
$this->{stringified} .= ':' . shift(@path);
else {
if ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
}
if ( scalar(@path) ) {
if ( defined $path[0] ) {
$this->{stringified} .= '[';
if ( ref( $path[0] ) eq 'HASH' ) {
my @selectorparts;
while ( my ( $key, $value ) =
each %{ $path[0] } )
{
push( @selectorparts,
$key . '=\'' . $value . '\'' );
$this->{stringified} = '\''
. $this->{stringified} . '\'/'
. $this->{tompath}->[0];
if ( $this->{tompath}->[1] ) {
my @path = @{ $this->{tompath} };
my $root = shift(@path);

if ( $root eq 'META' and scalar(@path) ) {
$this->{stringified} .= ':' . shift(@path);
}
if ( scalar(@path) ) {
if ( defined $path[0] ) {
$this->{stringified} .= '[';
if ( ref( $path[0] ) eq 'HASH' ) {
my @selectorparts;
while ( my ( $key, $value ) =
each %{ $path[0] } )
{
push( @selectorparts,
$key . '=\'' . $value . '\'' );
}
$this->{stringified} .=
join( ' AND ', @selectorparts );
shift(@path);
}
else {
ASSERT( $path[0] =~ /^\d+$/ ) if DEBUG;
$this->{stringified} .= shift(@path);
}
$this->{stringified} .=
join( ' AND ', @selectorparts );
shift(@path);
$this->{stringified} .= ']';
}
else {
ASSERT( $path[0] =~ /^\d+$/ ) if DEBUG;
$this->{stringified} .= shift(@path);
shift @path;
}
if ( scalar(@path) ) {
ASSERT( scalar(@path) == 1 ) if DEBUG;
$this->{stringified} .= '.' . shift(@path);
}
$this->{stringified} .= ']';
}
else {
shift @path;
}
if ( scalar(@path) ) {
ASSERT( scalar(@path) == 1 ) if DEBUG;
$this->{stringified} .= '.' . shift(@path);
}
ASSERT( not scalar(@path) ) if DEBUG;
}
ASSERT( not scalar(@path) ) if DEBUG;
}
}
elsif ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
}
}
elsif ( defined $this->{rev} ) {
$this->{stringified} .= '@' . $this->{rev};
else {
$this->{stringified} .= $this->{stringifiedwebsep};
}
}
else {
ASSERT( $this->{webpath} );
$this->{stringified} .= $this->{stringifiedwebsep};
ASSERT( $this->{root} );
$this->{stringified} = '/';
}
}
print STDERR "stringify(): $this->{stringified}\n"
Expand Down

0 comments on commit 3c3e222

Please sign in to comment.