* Nick Tonkin <[EMAIL PROTECTED]> [2002-07-30 10:00]:
> 
> On Tue, 30 Jul 2002, darren chamberlain wrote:
> 
> > So after all the hullabaloo about commify a few weeks ago, I took a
> > little while last night to write a plugin/filter wrapper around
> > Number::Format. 
> > 
> > Comments?
> 
> Perfect.

Now, *that's* a good comment. :)

> One question, though: Number::Format takes its constructor args
> in CAPS; your plugin appears to want lowercase. Any reason for the
> change? A TT thing about CAPS, I'm guessing?

Actually, the examples were taken directly from the perldocs, and,
anyway, new() does accept lower case options:

    
  # From Number/Format.pm:
     316     foreach $arg (qw(thousands_sep decimal_point mon_thousands_sep
     317                      mon_decimal_point int_curr_symbol decimal_digits
     318                      decimal_fill neg_format kilo_suffix mega_suffix
     319                      giga_suffix))
     320     {
     321         foreach ($arg, uc $arg, "-$arg", uc "-$arg")
     322         {
     323             next unless defined $args{$_};
     324             $me->{$arg} = $args{$_};
     325             delete $args{$_};
     326             last;
     327         }
     328     }


new() upcases the arguments passed to the constructor.

> One other thought occurs: I always define a Number::Format object
> globally in my apps since it's not going to change and you're just
> going to access its methods. Something like:

*nods*

> use vars qw($fnum);
> $fnum = Number::Format->new() unless $fnum;
> 
> Does TT take care of not reinstantiating unnecessarily, or is there a
> way to make it do that?

The Number::Format instance is created in
Template::Plugin::Number::Format::init(), which gets called from the
first USE line, and creates a series of closures that are attached to
the Template::Context object; I'm a little uncertain about whether
this object persists.  I think it should (there would still be
references to it in the Context, even though the enclosing T::P::N::F
instance goes out of scope), until the next USE Number.Format call: 
successive USE Number.Format lines will redefine the closures, so the
old object will go out of scope and be GC'ed.  From there, each filter
call uses the same Number::Format instance.  How that will actually end
up working, in terms of whether the same Number::Format object persists
between calls, I'm not fully sure, but within the same template, each
filter definitely uses the same object.

Which, of course, is only half an answer.  Sorry...

(darren)

-- 
You can put a man through school, but you cannot make him think.
    -- Ben Harper

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to