* Robert Brook <mail at robertbrook.com> [2004/03/09 11:50]:
> But when I view the (HTML) page, I get '1's returned in the source. I
> can suppress this output using CALL:
>
> [% CALL fh.print("my new line here\n") %]
>
> But, well, I'm lazy I want to be able to do that by default. How can I
> suppress that '1' reponse an the Plugin level?

Since open, print, and close return 1, that is what is emitted into the
template.  You can use CALL, as you figured out, or you can wrap all of
those methods in your plugin:

  package Template::Plugin::IO::File;
  # as before, and then:
  sub open {
      my $self = shift;
      $self->open(@_);
      return;
  }

  sub print {
      my $self = shift;
      $self->print(@_);
      return;
  }

  sub close {
      my $self = shift;
      $self->close(@_);
      return;
  }

  1;

You can also catch those with an AUTOLOAD:

  use vars qw($AUTOLOAD);
  sub AUTOLOAD {
      my $self = shift;
      (my $meth = $AUTOLOAD) =~ s/.*:://;

      $self->$meth(@_);
      return;
  }

For good measure, you might want to have those IO::File calls return
Template::Exceptions:

  use vars qw($AUTOLOAD);
  sub AUTOLOAD {
      my $self = shift;
      (my $meth = $AUTOLOAD) =~ s/.*:://;

      $self->$meth(@_) ||
          return Template::Exception->new('io.file', "$!");
      return;
  }

File operations do occasionally fail, you know.

(darren)

--
You cannot apply a technological solution to a sociological problem.
    -- Edwards' Law

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to