package Bryar::Frontend::ModPerl2;
use base 'Bryar::Frontend::Base';
use Apache::RequestRec;
use Apache::Request;

use Digest::MD5 qw(md5_hex);

use strict;
use warnings;
use Carp;
our $VERSION = '1.1';

=head1 NAME

MyFrontend - Apache mod_perl2 interface to Bryar

=head1 DESCRIPTION

This is a frontend to Bryar which is used when Bryar is being driven 
from Apache2.

=cut

sub obtain_url { Apache->request->uri() }
sub obtain_path_info { Apache->request->path_info() }
sub obtain_params {
  my $apr = Apache::Request->new(Apache->request);
  map { $_ => $apr->param($_) } $apr->param ;
}

sub send_data {
  my $self = shift; 
  #Apache->request->print(@_); 
  print(@_); 
}

sub send_header { 
  my ($self, $k, $v) = @_;
  if ($k eq "Content-type") {
    Apache->request->content_type($v);
  } elsif ($k eq "Status") {
    $v =~ /^([^ ]*) /;
    Apache->request->status($1)
  } else {
    Apache->request->headers_out->set($k, $v);
  }
}

sub get_header {
  my ($self, $header) = @_;
  Apache->request->headers_in->get($header);
}

sub _etag {
    my ($self, $data) = @_;
    my $req_tag = $self->get_header("If-None-Match") || "";
    my $etag = '"'.md5_hex($data).'"';
    $self->send_header('ETag', $etag);
    return $etag eq $req_tag;
}

#sub report_error {
#    my ($class, $title, $message) = @_;
#    warn($message);
#}


1;

=head1 LICENSE

This module is free software, and may be distributed under the same
terms as Perl itself.

=head1 AUTHOR

Copyright (C) 2003, Simon Cozens C<simon@kasei.com>

