[Templates-cvs] cvs commit: TT3/lib/Template/TT3 Factory.pm

cvs@template-toolkit.org cvs@template-toolkit.org
Thu, 04 Dec 2003 15:57:23 +0000


cvs         03/12/04 15:57:22

  Modified:    lib/Template/TT3 Factory.pm
  Log:
  * updated docs
  
  Revision  Changes    Path
  1.3       +30 -14    TT3/lib/Template/TT3/Factory.pm
  
  Index: Factory.pm
  ===================================================================
  RCS file: /template-toolkit/TT3/lib/Template/TT3/Factory.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Factory.pm	2003/12/04 15:48:42	1.2
  +++ Factory.pm	2003/12/04 15:57:21	1.3
  @@ -16,7 +16,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Factory.pm,v 1.2 2003/12/04 15:48:42 abw Exp $
  +#   $Id: Factory.pm,v 1.3 2003/12/04 15:57:21 abw Exp $
   #
   # TODO
   #   * if module entry can be a string or hash table, then module() could
  @@ -35,7 +35,7 @@
   use vars qw( $VERSION $DEBUG $ERROR $WARNING $UTILS $MODULES );
   use base qw( Template::TT3::Base );
   
  -$VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  +$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
   $DEBUG   = 0 unless defined $DEBUG;
   $ERROR   = '';
   $UTILS   = 'Template::TT3::Utils';
  @@ -205,8 +205,24 @@
   
       use Template::TT3::Factory
   
  -    # TODO
  +    my $factory = Template::TT3::Factory->new(
  +        modules => {
  +            foo => 'My::Foo::Module',
  +            bar => 'My::Bar::Module',
  +            wiz => {
  +                module => 'My::Wiz::Module',
  +                class  => 'My::Wiz::Class',
  +            }
  +        },
  +    );
  +
  +    my $foo = $factory->create( foo => $arg1, $arg2 )
  +        || die $factory->error();
   
  +    my $bar = $factory->create( bar => $arg1, $arg2 )
  +        || die $factory->error();
  +
  +
   =head1 DESCRIPTION
   
   This module implements a factory for loading other Template Toolkit
  @@ -257,8 +273,8 @@
   with those provided by the C<modules> parameter.
   
   The C<create()> method can then be used to create an object of one of the 
  -classed managed by the factory object.  The first argument denotes the 
  -simple name of the required module.  Any additional arguments are forwarded
  +classes managed by the factory object.  The first argument denotes the 
  +short name of the required module.  Any additional arguments are forwarded
   to the appropriate constructor.
   
       my $foo = $factory->create( foo => 10, 20 )
  @@ -292,7 +308,7 @@
       );
   
   When the C<create()> method is called, the C<My::Foo::Module> will be 
  -loaded, but the new method will be called against C<My::Foo::Class>.
  +loaded, but the C<new()> method will be called against C<My::Foo::Class>.
   So our earlier example:
   
       my $foo = $factory->create( foo => 10, 20 )
  @@ -342,8 +358,8 @@
   =head2 module()
   
   This method is used to get and set module entries in the factory object.
  -It can be called with two argument as shown in the next example.  The first
  -argument is a simple name for the module, the second argument is the full
  +It can be called with two arguments as shown in the next example.  The first
  +argument is a short name for the module, the second argument is the full
   name of the Perl module that implements it.
   
       $factory->module( wiz => 'My::Wiz::Module' );
  @@ -369,7 +385,7 @@
       print $module->{ class  };              # My::Wiz::Class
   
   When the method is called with a single argument to retrieve a module,
  -the corresponding Perl module (if one is defined) is itself loaded in 
  +the corresponding Perl module (if one is defined) is loaded in 
   preparation for use.
   
   =head2 class($name)
  @@ -378,6 +394,10 @@
   as a hash reference then the C<class> item is used.  Otherwise the module
   name is used.
   
  +    print $factory->class('foo');   # My::Foo::Module
  +
  +    print $factory->class('wiz');   # My::Wiz::Class
  +
   =head2 create()
   
   This method instantiates an object of a class managed by the factory.
  @@ -395,7 +415,7 @@
   
   =head1 VERSION
   
  -$Revision: 1.2 $
  +$Revision: 1.3 $
   
   =head1 COPYRIGHT
   
  @@ -404,10 +424,6 @@
   
   This module is free software; you can redistribute it and/or
   modify it under the same terms as Perl itself.
  -
  -=head1 SEE ALSO
  -
  -# TODO
   
   =cut