This next example shows how to load and return non-text based content. A
random image file is selected and returned as the response data of the Page
object.
package ImageTest;
use strict;
use warnings;
our @ISA = qw(Org::Bgw::Pas::Page);
use Org::Bgw::Pas::SessionPage;
sub execute
{
my($self) = @_;
my @files = qw(
linux.png
freebsd.png
netbsd.png
openbsd.png
bsdi.png
mach.png
aix.png
irix.png
true64.png
sco.png
solaris.png
xenix.png
svr4.png
multics.png
plan9.png
lynx.png
);
my $file = $files[ rand @files ];
$self->response->content_type("image/png");
$self->response->print( $self->getFileAsScalar( $file ) );
return 1;
}
1;
|