| 1 | package QBit::WebInterface::Response; | ||
| 2 | $QBit::WebInterface::Response::VERSION = '0.033'; | ||
| 3 | use qbit; | ||
| 4 | |||
| 5 | use base qw(QBit::Class); | ||
| 6 | |||
| 7 | use CGI::Cookie; | ||
| 8 | |||
| 9 | __PACKAGE__->mk_accessors( | ||
| 10 | qw( | ||
| 11 | content_type | ||
| 12 | cookies | ||
| 13 | data | ||
| 14 | filename | ||
| 15 | location | ||
| 16 | status | ||
| 17 | headers | ||
| 18 | timelog | ||
| 19 | ) | ||
| 20 | ); | ||
| 21 | |||
| 22 | sub init { | ||
| 23 | my ($self) = @_; | ||
| 24 | |||
| 25 | $self->content_type('text/html; charset=UTF-8'); | ||
| 26 | $self->cookies({}); | ||
| 27 | $self->headers({}); | ||
| 28 | } | ||
| 29 | |||
| 30 | sub add_cookie { | ||
| 31 | my ($self, $name, $value, %opts) = @_; | ||
| 32 | |||
| 33 | $self->cookies->{$name} = CGI::Cookie->new( | ||
| 34 | -name => $name, | ||
| 35 | -value => $value, | ||
| 36 | (map {'-' . $_ => $opts{$_}} grep {exists($opts{$_})} qw(expires domain path secure)), | ||
| 37 | ); | ||
| 38 | } | ||
| 39 | |||
| 40 | sub delete_cookie { | ||
| 41 | my ($self, $name) = @_; | ||
| 42 | |||
| 43 | $self->cookies->{$name} = CGI::Cookie->new( | ||
| 44 | -name => $name, | ||
| 45 | -value => '', | ||
| 46 | expires => '-10Y', | ||
| 47 | ); | ||
| 48 | } | ||
| 49 | |||
| 50 | TRUE; |