Changes

From SME Server
Jump to navigationJump to search
12 bytes added ,  16:51, 20 December 2013
Line 10: Line 10:  
== SYNOPSIS ==
 
== SYNOPSIS ==
 
         use Text::Template;
 
         use Text::Template;
 
+
 
         $template = Text::Template->new(TYPE => ’FILE’,  SOURCE => ’filename.tmpl’);
 
         $template = Text::Template->new(TYPE => ’FILE’,  SOURCE => ’filename.tmpl’);
 
         $template = Text::Template->new(TYPE => ’ARRAY’, SOURCE => [ ... ] );
 
         $template = Text::Template->new(TYPE => ’ARRAY’, SOURCE => [ ... ] );
Line 16: Line 16:  
         $template = Text::Template->new(TYPE => ’STRING’, SOURCE => ’...’ );
 
         $template = Text::Template->new(TYPE => ’STRING’, SOURCE => ’...’ );
 
         $template = Text::Template->new(PREPEND => q{use strict;}, ...);
 
         $template = Text::Template->new(PREPEND => q{use strict;}, ...);
 
+
 
         # Use a different template file syntax:
 
         # Use a different template file syntax:
 
         $template = Text::Template->new(DELIMITERS => [$open, $close], ...);
 
         $template = Text::Template->new(DELIMITERS => [$open, $close], ...);
 
+
 
         $recipient = ’King’;
 
         $recipient = ’King’;
 
         $text = $template->fill_in();  # Replaces ‘{$recipient}’ with ‘King’
 
         $text = $template->fill_in();  # Replaces ‘{$recipient}’ with ‘King’
 
         print $text;
 
         print $text;
 
+
 
         $T::recipient = ’Josh’;
 
         $T::recipient = ’Josh’;
 
         $text = $template->fill_in(PACKAGE => T);
 
         $text = $template->fill_in(PACKAGE => T);
 
+
 
         # Pass many variables explicitly
 
         # Pass many variables explicitly
 
         $hash = { recipient => ’Abed-Nego’,
 
         $hash = { recipient => ’Abed-Nego’,
Line 37: Line 37:  
         # @friends is ( ’me’, ’you’ ),
 
         # @friends is ( ’me’, ’you’ ),
 
         # %enemies is ( loathsome => ..., fearsome => ... )
 
         # %enemies is ( loathsome => ..., fearsome => ... )
 
+
 
         # Call &callback in case of programming errors in template
 
         # Call &callback in case of programming errors in template
 
         $text = $template->fill_in(BROKEN => \&callback, BROKEN_ARG => $ref, ...);
 
         $text = $template->fill_in(BROKEN => \&callback, BROKEN_ARG => $ref, ...);
 
+
 
         # Evaluate program fragments in Safe compartment with restricted permissions
 
         # Evaluate program fragments in Safe compartment with restricted permissions
 
         $text = $template->fill_in(SAFE => $compartment, ...);
 
         $text = $template->fill_in(SAFE => $compartment, ...);
 
+
 
         # Print result text instead of returning it
 
         # Print result text instead of returning it
 
         $success = $template->fill_in(OUTPUT => \*FILEHANDLE, ...);
 
         $success = $template->fill_in(OUTPUT => \*FILEHANDLE, ...);
 
+
 
Parse template with different template file syntax:
 
Parse template with different template file syntax:
 
         $text = $template->fill_in(DELIMITERS => [$open, $close], ...);
 
         $text = $template->fill_in(DELIMITERS => [$open, $close], ...);
 
         # Note that this is *faster* than using the default delimiters
 
         # Note that this is *faster* than using the default delimiters
 
+
 
         # Prepend specified perl code to each fragment before evaluating:
 
         # Prepend specified perl code to each fragment before evaluating:
 
         $text = $template->fill_in(PREPEND => q{use strict ’vars’;}, ...);
 
         $text = $template->fill_in(PREPEND => q{use strict ’vars’;}, ...);
 
+
 
         use Text::Template ’fill_in_string’;
 
         use Text::Template ’fill_in_string’;
 
         $text = fill_in_string( <<EOM, PACKAGE => ’T’, ...);
 
         $text = fill_in_string( <<EOM, PACKAGE => ’T’, ...);
Line 64: Line 64:  
         use Text::Template ’fill_in_file’;
 
         use Text::Template ’fill_in_file’;
 
         $text = fill_in_file($filename, ...);
 
         $text = fill_in_file($filename, ...);
 
+
 
         # All templates will always have ‘use strict vars’ attached to all fragments
 
         # All templates will always have ‘use strict vars’ attached to all fragments
 
         Text::Template->always_prepend(q{use strict ’vars’;});
 
         Text::Template->always_prepend(q{use strict ’vars’;});

Navigation menu