# -------------------------------------------------------------------------------------
# flo::Template::Anchor
# -------------------------------------------------------------------------------------
#
#       Author : Jean-Michel Hiver (jhiver@cisedi.com).
#    Copyright : (c) MKDoc Holdings Ltd, 2000.
# 
#      Unauthorized modification, use, reuse, distribution or redistribution
#      of this module is stricly forbidden.
#
#    Description:
#
#      This tags allows you to write links which are hyperlinked only in the case
#      where you are not on the same page as the link itself.
#
#      Usage: <% a href="/foo/bar" title="Foo Bar" %>Hyperlink<% end-a %>
#
# -------------------------------------------------------------------------------------
package flo::Template::Anchor;
use lib::Template::AbstractBalancedTag;
use lib::Exception;
use lib::Template;
use lib::cgi::CGI;
use strict;
use vars qw /@ISA/;
@ISA = qw /lib::Template::AbstractBalancedTag/;


##
# $obj->main;
# -----------
#   Parses and displays the value of a variable.
#   <% sticker name="my.nifty.sticker" %>
##
sub main
{
    my $self   = shift;
    my $result = $self->result;
    my $tokens = $self->tokens;
    
    # parses $tokens to extract the Anchor data
    my ($info, $data) = $self->parse ($tokens);
    
    # which variable do we want to test ?
    my $href = $info->{href} or
	throw (new lib::Exception ( code => 'VARIABLE_NOT_SET',
				    info => "should have an 'href' attribute" ) );
    
    my $cgi  = lib::cgi::CGI->get;
    my $cgix = $cgi->new;
    $cgix->path_info ($href);
    $href = $cgix->self_url;
    
    my $title = $info->{title};
    
    my $res = $self->{class}->new ( data => $data, hash => $self->{hash} )->parse;
    
    # we want to link only if the paths aren't the same
    if ($cgix->path_info ne $cgi->path_info)
    {
	if (defined $title and $title)
	{
	    $res = "<a href=\"$href\" title=\"$title\">" . $res . "</a>";
	}
	else
	{
	    $res = "<a href=\"$href\">" . $res . "</a>";
	}
    }
    
    push @{$result}, $res;
}


1;







