NAME

Text::UberText::Dispatch - UberText Code Dispatcher

DESCRIPTION

Text::UberText::Dispatch keeps track of loaded code modules that extend the UberText template language. A Dispatch object is automatically created for new Text::UberText objects.

EXTENDING UBERTEXT

If you write a module that integrates with an UberText template, the UberText object needs to be aware of it.

$uber=Text::UberText->new();

$uber->extend($myObject);

$uber->extend(MyClass);

The UberText module passes the object or class name to the Text::UberText::Dispatch object. The Dispatch object then calls the uberText method of the module it was passed.

The uberText method will need to return 3 variables. The first is the object that the dispatch table will need to use when it encounters your custom namesapce. The second variable is the preferred namespace the object will use, and the third is an anonymous hash containing the dispatch table matching UberText tags and Perl code.

EXAMPLE

Custom Module

package Automobile;
$Dispatch={
"make" => \&make,
"model" => \&model,
"color" => \&color,
"odometer' => \&mileage,
};
sub uberText
{
my ($self)=shift;
return ($self,"my.automobile",$Dispatch);
}
sub make
{
my ($self)=shift;
return ($self->{color});
}
sub mileage
{
my ($self,$node)=@_;
my ($value);
if ($node->commandValue() eq "trip")
{
$value=$self->{odometer}->{trip};
} else {
$value=$self->{odometer}->{basic};
}
if ($node->getOptValue("units") eq "metric")
{
# convert miles to kilometers
$value=$value*1.61;
}
return $value;
}

UberText File

The manufacturer of my car is [my.automobile make ]
It is described as a [my.automobile color ] [my.automobile model ].
My last trip was [my.automobile odometer:(trip) units:(metric) ] kilometers.

METHODS

$dispatch->extend($module)

When a class name is passed to the Dispatch object, the module is loaded, and the uberText() method is called. When a blessed object is passed, the loading isn't necessary, so only the uberText() method is called.

Based on the data returned from UberText, the data returned from the uberText() method is saved in the internal dispatch table.

$dispatch->involke($node);

Takes the internal data from a Command node, and then runs the command associated with the namespace.

$dispatch->fetch($namespace);

Returns the object in the dispatch table assigned to a particular UberText namespace.

AUTHOR

Chris Josephes <cpj1@visi.com>

SEE ALSO

Text::UberText

COPYRIGHT

Copyright 2002, Chris Josephes. All rights reserved. This module is free software. It may be used, redistributed, and/or modified under the same terms as Perl itself. ~