package Bryar::Frontend::Mod_perl2;
use base 'Bryar::Frontend::Base';
use Apache2::RequestUtil;
use Apache2::Request;

use Digest::MD5 qw(md5_hex);

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

=head1 NAME

ModPerl2 - 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 { Apache2::RequestUtil->request->uri() }
sub obtain_path_info { Apache2::RequestUtil->request->path_info() }
sub obtain_params {
  my $apr = Apache2::Request->new(Apache2::RequestUtil->request);
  map { $_ => $apr->param($_) } $apr->param ;
}

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

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

sub get_header {
  my ($self, $header) = @_;
  Apache2::RequestUtil->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>
Copyright (C) 2004, Matijs van Zuijlen C<mvz@xs4all.nl>
