start fixing test for multi cat phenotype upload.
[sgn.git] / lib / CXGN / Scrap / AjaxPage.pm
blob48ebab8d26f137d48dd2b0f7c473d407c3e38eb1
2 =head1 NAME
4 CXGN::Scrap::AjaxPage
6 =head1 DESCRIPTION
8 A subclass of CXGN::Scrap, which is the superclass of CXGN::Page, this module performs a few actions in the constructor appropriate for Ajax Pages.
9 Use this as a Page module replacement for scripts that don't produce much output and are called asynchronously.
11 =head1 OBJECT METHODS
13 =head2 new
15 Creates a new AjaxPage object. Receives a content type as an optional argument, which defaults to "text/xml"
17 #Example
18 my $AjaxPage = CXGN::Scrap::AjaxPage->new();
19 $AjaxPage->send_http_header() default "text/xml"
20 print $AjaxPage->header();
21 print "<option name="candy">cookie</option>"
22 print $AjaxPage->footer();
24 =head1 AUTHORS
26 Christopher Carpita <csc32@cornell.edu>
28 =cut
30 package CXGN::Scrap::AjaxPage;
31 use base qw/CXGN::Scrap/;
32 use strict;
34 sub new {
35 my $class = shift;
36 my $self = $class->SUPER::new();
37 $self->{content_type} = shift || 'application/json';
38 return $self;
41 sub send_http_header {
42 my $self = shift;
43 $self->send_content_type_header();
46 sub header {
47 my $self = shift;
48 $self->{doc_header_called} = 1;
49 my $extra_head = shift;
50 my $caller = $self->caller();
51 # if ($caller) {
52 # $extra_head = "<caller>$caller</caller>\n" . $extra_head;
53 # }
54 # chomp $extra_head;
55 # my $header = <<XML;
56 #<?xml version="1.0" encoding="UTF-8"?>
57 #<scrap>
58 #$extra_head
59 #XML
60 return undef;
63 sub footer {
64 my $self = shift;
65 $self->{doc_footer_called} = 1;
66 my $extra_foot = shift;
67 # chomp $extra_foot;
68 # return "$extra_foot\n</scrap>";
71 sub caller {
72 my $self = shift;
73 my $caller = shift;
74 $self->{caller} = $caller if $caller;
75 return $self->{caller};
78 sub throw {
79 my ( $self, $message ) = @_;
80 print $self->header() unless $self->{doc_header_called};
81 print "<error>$message</error>";
82 print $self->footer();
83 exit(-1);
86 ####
87 1; # do not remove
88 ####