# -------------------------------------------------------------------------------------
# flo::Template::Component
# -------------------------------------------------------------------------------------
#
#       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.
#
#      Provides the implementation for the
#      <% component class="TEXT, HTML"
#                 [ number="1" ]
#                 [ remove="1" ]
#                   set="SomeVariable" %> Tag.
#
# -------------------------------------------------------------------------------------
package flo::Template::Component;
use lib::Template::AbstractTag;
use lib::Exception;
use lib::Template;
use flo::Editor;
use strict;
use vars qw /@ISA/;
@ISA = qw /lib::Template::AbstractTag/;


sub main
{
    my $self = shift;
    my $result = $self->result;
    my $tokens = $self->tokens;    
    my ($token_name, $token_info) = $self->parse_tag (shift @{$tokens});
    
    my $component_classes = $token_info->{class}  || 0;
    my $component_number  = $token_info->{number} || 0;
    my $must_remove       = $token_info->{remove} || 0;
    my $set_symbol        = $token_info->{set} or
	throw (new lib::Exception (code => "NO_SYMBOL_SET",
				   info => $self ) );
    
    my @component_classes = ();
    if ($component_classes)
    {
	@component_classes = split /,/, $component_classes;
	foreach my $component_class (@component_classes)
	{
	    $component_class =~ s/^\s+//;
	    $component_class =~ s/\s+$//;
	}
    }
    
    # grab the result and sets it
    my $editor = $flo::Editor::ETERNAL;
    if ($component_number)
    {
	$lib::Template::STASH->{$set_symbol} = $editor->access ( class  => \@component_classes,
								 number => $component_number,
								 remove => $must_remove );
    }
    else
    {
	my @loop = $editor->access ( class  => \@component_classes,
				     number => $component_number,
				     remove => $must_remove );

	$lib::Template::STASH->{$set_symbol} = \@loop;
    }
}


1;
