Mahiro Ando > EJS-Template > EJS::Template::IO

Download:
EJS-Template-0.08.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

EJS::Template::IO - Mix-in module to normalize input/output parameters for EJS::Template

Methods ^

input

Normalizes input.

    $self->input('filepath.ejs');
    $self->input(\$source_text);
    $self->input($input_handle);
    $self->input(\*STDIN);

It returns a list in the form ($input, $should_close), where $input is the normalized input handle and $should_close indicates the file handle has been opened and your code is responsible for closing it.

Alternatively, a callback can be given as the second argument, which will be invoked with its argument set to the normalized $input.

    $self->input('filepath.ejs', sub {
        my ($input) = @_;
        while (<$input>) {
            ...
        }
    });

If $input is a file handle that has been opened by this input() method, then it will be closed automatically after the callback returns. Even if die() is invoked within the callback, the file handle will be closed if necessary, and then this input() method will forward die($@).

output

Normalizes output.

   $self->output('filepath.out');
   $self->output(\$result_text);
   $self->output($output_handle);
   $self->output(\*STDOUT);

It returns a list in the form ($output, $should_close), where $output is the normalized output handle and $should_close indicates the file handle has been opened and your code is responsible for closing it.

Alternatively, a callback can be given as the second argument, which will be invoked with its argument set to the normalized $output.

    $self->output('filepath.out', sub {
        my ($output) = @_;
        while (<$output>) {
            ...
        }
    });

If $output is a file handle that has been opened by this output() method, then it will be closed automatically after the callback returns. Even if die() is invoked within the callback, the file handle will be closed if necessary, and then this output() method will forward die($@).

print

Prints text to the current output target.

It can be invoked only within an execution context where the output file handle is open.

    $self->output('filepath.out', sub {
        $self->print(...);
    });

SEE ALSO ^

syntax highlighting: