PDA

View Full Version : Re: Re: [slim] New plugin for wma streaming on windows



John A. Tamplin
2003-12-03, 12:39
On Wed, 3 Dec 2003, Caleb Epstein wrote:

> What about some code that would try and dynamically load a
> the module Slim::Formats::$type; something like:
>
> # Keep track of dynamic formats that have been loaded
> if (not exists $DYNFORMATS{$type}) {
> eval "use Slim::Formats::$type";
> $DYNFORMATS{$type} = length $@ ? 0 : 1;
> }
>
> # If we successfully loaded a handler for this type, use it
> if ($DYNFORMATS{$type}) {
> $tempCacheEntry =
> eval "Slim::Formats::$type::get_tags (\$filepath)";
> }
>
> This will require that the primary interface to
> Slim::Formats::<whatever> is a method called "get_tags".

Rather than eval'ing the common case, why not make these handlers objects?
That way you only do the expense part once for each type. Ie:

if(not exists $DYNFORMATS{$type}) {
$obj=undef;
eval "use Slim::Formats::$type; $obj=new Slim::Formats::$type";
$DYNFORMATS{$type}=$obj;
}
if($obj=$DYNFORMATS{$type}) {
$tempCacheEntry=$obj->get_tags($filepath);
}

--
John A. Tamplin jat (AT) jaet (DOT) org
770/436-5387 HOME 4116 Manson Ave
Smyrna, GA 30082-3723