MetaStore::Response - Response class


MetaStore documentation Contained in the MetaStore distribution.

Index


Code Index:

NAME

Top

MetaStore::Response - Response class

SYNOPSIS

Top

  use MetaStore::Response;

DESCRIPTION

Top

Class for set response headers. Add functionality to return context.

METHODS

Top

json

AUTHOR

Top

Zahatski Aliaksandr, <zag@cpan.org>


MetaStore documentation Contained in the MetaStore distribution.
package MetaStore::Response;

#$Id: Response.pm 927 2010-12-22 14:53:53Z zag $

use Data::Dumper;
use WebDAO::Response;
use JSON;
use base qw( WebDAO::Response );
__PACKAGE__->attributes qw/  __json __html __xml /;
use strict;

sub json : lvalue {
    my $self = shift;
    $self->{__json};
}


sub raw : lvalue {
    my $self = shift;
    $self->{__raw};
}

sub html : lvalue {
    my $self = shift;
    $self->{__html};
}

sub xml : lvalue {
    my $self = shift;
    $self->{__xml};
}

sub js : lvalue {
    my $self = shift;
    $self->{__jscript};
}

sub _print_dep_on_context {
    my ( $self, $session ) = @_;
    my $accept = $session->Cgi_env->{accept};
    my $res ;
    if ( exists $accept->{'application/javascript'} ) {
        $res = $self->json;
        $res = to_json($res) unless  ref($res) eq 'CODE';
    } else {
        $res = $self->html
    }
    #print if defined result
    $self->print( ref($res) eq 'CODE' ? $res->() : $res ) if defined $res;
}

sub _destroy {
    my $self = shift;
    $self->{__js} = undef;
    $self->{__json} = undef;
    $self->{__html} = undef;
    $self->{__xml} = undef;
    $self->{__raw}= undef; 
#    $self->auto( [] );
}
1;
__END__