package Apache::ParseSource;

use strict;
use Apache::Build ();
use Config ();

our $VERSION = '0.02';


sub prefixlist {
    return [qw(ap_ apr_)] ;
}

sub unwanted_includes {
    return [qw(ap_listen internal version
                                apr_optional mod_include
                                mod_ssl ssl_)] ;
}


sub includes { shift->config->includes }

sub new {
    my $class = shift;

    
    my $self = SUPER::new (@_) ;
    $self -> {config} = Apache::Build->build_config ;

    $Apache::Build::APXS ||= $self->{apxs};

    $self;
}

sub config {
    shift->{config};
}


sub include_dirs {
    my $self = shift;
    ($self->config->apxs(-q => 'INCLUDEDIR'),
     $self->config->mp_include_dir);
}

sub includes { shift->config->includes }

sub cscan_filename { '.apache_includes' } ;

sub sort_includes {
    my $includes = shift ;
    #include apr_*.h before the others
    my @wanted = grep { /apr_\w+\.h$/ } @$includes;
    push @wanted, grep { !/apr_\w+\.h$/ } @$includes;

    return \@wanted ;
}




my $filemode = join '|',
  qw{READ WRITE CREATE APPEND TRUNCATE BINARY EXCL BUFFERED DELONCLOSE};

sub defines_wanted {

    my $self = shift ;

    return $self -> {defines_wanted} if ($self -> {defines_wanted}) ;

    $self -> {defines_wanted} = {
        Apache => {
            common     => [qw{OK DECLINED DONE}],
            methods    => [qw{M_ METHODS}],
            options    => [qw{OPT_}],
            satisfy    => [qw{SATISFY_}],
            remotehost => [qw{REMOTE_}],
            http       => [qw{HTTP_}],
    #       config     => [qw{DECLINE_CMD}],
    #       types      => [qw{DIR_MAGIC_TYPE}],
            override   => [qw{OR_ ACCESS_CONF RSRC_CONF}],
            log        => [qw(APLOG_)],
        },
        APR => {
            poll      => [qw{APR_POLL}],
            common    => [qw{APR_SUCCESS}],
            error     => [qw{APR_E}],
            fileperms => [qw{APR_\w(READ|WRITE|EXECUTE)}],
            finfo     => [qw{APR_FINFO_}],
            filepath  => [qw{APR_FILEPATH_}],
            filemode  => ["APR_($filemode)"],
            flock     => [qw{APR_FLOCK_}],
            socket    => [qw{APR_SO_}],
            limit     => [qw{APR_LIMIT}],
            hook      => [qw{APR_HOOK_}],
            uri       => [qw{APR_URI_}],
        },
    } ;

);



sub defines_unwanted {
    return join '|', qw{HTTP_VERSION APR_EOL_STR APLOG_MARK};
    }


sub enums_wanted {
    {
    Apache => { map { $_, 1 } qw(cmd_how input_mode filter_type) },
    APR => { map { $_, 1 } qw(shutdown_how read_type) },
    }
};


sub get_constants {

    my($self) = @_;
    my $constants = $self -> SUPER::handle_constant ($self) ;

    #maintain a few handy shortcuts from 1.xx
    #aliases are defined in ModPerl::Code
    push @{ $constants->{'Apache'}->{common} },
      qw(NOT_FOUND FORBIDDEN AUTH_REQUIRED SERVER_ERROR);

    return $constants;
}




sub handle_enum_name {
    my($self, $name) = @_;

    $name =~ s/^ap_//;
    $name =~ s/_(e|t)$//;
    $name =~ s/^apr_//;

    return $name ;
}


sub wanted_structures { shift->{prefix_re} . '|(' .join '|', qw(_rec module
                              piped_log uri_components htaccess_result
                              cmd_parms cmd_func cmd_how) . ')' ;
}


sub package { 'Apache' } 

sub targetdir { 'xs/tables/current' }


1;
__END__

