ClearPress
view release on metacpan or search on metacpan
lib/ClearPress/view.pm view on Meta::CPAN
if(defined $val) {
$self->{output_finished} = $val;
$DEBUG_OUTPUT and carp "output_finished = $val";
}
return $self->{output_finished};
}
sub output_end {
my $self = shift;
$DEBUG_OUTPUT and carp "output_end: $self";
$self->output_finished(1);
return $self->output_flush;
}
sub output_reset {
my $self = shift;
$self->{output_buffer} = [];
$DEBUG_OUTPUT and carp 'output_reset';
return;
}
sub actions {
my $self = shift;
my $content = q[];
$self->process_template('actions.tt2', {}, \$content);
return $content;
}
sub redirect {
my ($self, $url, $status) = @_;
$self->headers->header('Status', HTTP_FOUND);
$self->headers->header('Location', $url);
#########
# - reset all previously output but unflushed content
# - push headers down the pipe, and html redirects
# - finish up
#
$self->output_reset();
if($TRAP_REDIR_OVERFLOW) {
if(length $self->headers->as_string > $TRAP_REDIR_OVERFLOW) { # fudge for apparent buffer overflow with apache+mod_perl (ParseHeaders related?)
carp q[warning: header block looks long];
$self->headers->remove_header('Location');
$self->headers->header('Status', HTTP_OK);
}
}
$self->output_buffer($self->headers->as_string, "\n");
$self->decorator->meta_refresh(qq[0;URL='$url']);
#########
# clean everything up and terminate
#
$self->output_flush();
$self->headers->clear();
########
# Warning: This ought to correspond to content-type, but doesn't!
#
return <<"EOT"
<p>This document has moved <a href="$url">here</a>.</p>
<script>document.location.href="$url";</script>
EOT
}
#########
# automated method generation for core CRUD+ view methods
#
BEGIN {
no strict 'refs'; ## no critic (ProhibitNoStrict)
for my $ext (qw(xml ajax json csv)) {
for my $method (qw(create list read update delete options)) {
my $ns = sprintf q[%s_%s], $method, $ext;
*{$ns} = sub { my $self = shift; return $self->$method; };
}
}
}
1;
__END__
=head1 NAME
ClearPress::view - MVC view superclass
=head1 VERSION
$Revision: 470 $
=head1 SYNOPSIS
my $oView = ClearPress::view::<subclass>->new({util => $oUtil});
$oView->model($oModel);
print $oView->decor?
$oDecorator->header
:
q[Content-type: ].$oView->content_type."\n\n";
print $oView->render;
print $oView->decor?$oDecorator->footer:q[];
=head1 DESCRIPTION
View superclass for the ClearPress framework
=head1 SUBROUTINES/METHODS
=head2 new - constructor
my $oView = ClearPress::view::<subclass>->new({util => $oUtil, ...});
=head2 init - additional post-constructor hook
=head2 setup_filters - adds default tt_filters, called by ->new()
=head2 locales - hashref of locale lexicons to feed Locale::Maketext::Lexicon
( run in 1.338 second using v1.01-cache-2.11-cpan-524268b4103 )