You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@apache.org on 2002/06/02 20:41:54 UTC
cvs commit: xml-axkit/lib/Apache/AxKit ConfigReader.pm
matts 2002/06/02 11:41:54
Modified: . AxKit.xs
lib/Apache/AxKit ConfigReader.pm
Log:
Cleaned up some C code and moved ConfigReader to a more OO method of get_config
Revision Changes Path
1.4 +40 -21 xml-axkit/AxKit.xs
Index: AxKit.xs
===================================================================
RCS file: /home/cvs/xml-axkit/AxKit.xs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AxKit.xs 13 May 2002 19:33:28 -0000 1.3
+++ AxKit.xs 2 Jun 2002 18:41:54 -0000 1.4
@@ -1,4 +1,4 @@
-/* $Id: AxKit.xs,v 1.3 2002/05/13 19:33:28 kip Exp $ */
+/* $Id: AxKit.xs,v 1.4 2002/06/02 18:41:54 matts Exp $ */
#ifdef __cplusplus
extern "C" {
@@ -135,25 +135,6 @@
ap_remove_module(&XS_AxKit);
}
-SV *
-get_config (r)
- Apache r
- PREINIT:
- axkit_dir_config * cfg;
- HV * config;
- CODE:
- cfg = (axkit_dir_config *)
- ap_get_module_config(r->per_dir_config, &XS_AxKit);
-
- if (!cfg) {
- XSRETURN_UNDEF;
- }
-
- config = ax_get_config(cfg);
- RETVAL = newRV_noinc((SV*)config);
- OUTPUT:
- RETVAL
-
void
load_module (name)
char * name
@@ -174,6 +155,9 @@
char * uri
char * base
CODE:
+ if (r == NULL) {
+ croak("build_uri: Unexpected r == NULL");
+ }
RETVAL = axBuildURI(r->pool, uri, base);
OUTPUT:
RETVAL
@@ -187,7 +171,7 @@
SV * str;
int debuglevel;
axkit_dir_config * cfg;
- CODE:
+ PPCODE:
r = perl_request_rec(NULL);
if (r == NULL) {
return;
@@ -219,6 +203,41 @@
}
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, r, "[AxKit] %s", SvPV(str, n_a));
SvREFCNT_dec(str);
+
+
+MODULE = AxKit PACKAGE = Apache::AxKit::ConfigReader
+
+PROTOTYPES: DISABLE
+
+SV *
+_get_config (r=NULL)
+ Apache r
+ CODE:
+ {
+ axkit_dir_config * cfg;
+ HV * config;
+
+ if (r == NULL) {
+ croak("Unexpected request_rec = NULL");
+ }
+
+ cfg = (axkit_dir_config *)
+ ap_get_module_config(r->per_dir_config, &XS_AxKit);
+
+ if (!cfg) {
+ config = newHV();
+ }
+ else {
+ config = ax_get_config(cfg);
+ if (!config) {
+ config = newHV();
+ }
+ }
+ RETVAL = newRV_noinc((SV*)config);
+ }
+ OUTPUT:
+ RETVAL
+
#ifdef HAVE_LIBXML2
1.7 +21 -9 xml-axkit/lib/Apache/AxKit/ConfigReader.pm
Index: ConfigReader.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/ConfigReader.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConfigReader.pm 27 May 2002 13:31:20 -0000 1.6
+++ ConfigReader.pm 2 Jun 2002 18:41:54 -0000 1.7
@@ -1,4 +1,4 @@
-# $Id: ConfigReader.pm,v 1.6 2002/05/27 13:31:20 matts Exp $
+# $Id: ConfigReader.pm,v 1.7 2002/06/02 18:41:54 matts Exp $
package Apache::AxKit::ConfigReader;
@@ -10,11 +10,11 @@
my $class = shift;
my $r = shift;
- my $cfg = AxKit::get_config($r);
- if (!$cfg) {
- $cfg = {};
- AxKit::Debug(2, "Unable to get_config(). Using blank hashref instead");
- }
+# my $cfg = AxKit::get_config($r);
+# if (!$cfg) {
+# $cfg = {};
+# AxKit::Debug(2, "Unable to get_config(). Using blank hashref instead");
+# }
# use Apache::Peek 'Dump';
# Dump($cfg);
@@ -22,13 +22,25 @@
# $Data::Dumper::Indent = 1;
# warn("Cfg: ", Data::Dumper->Dump([$cfg], ['cfg']));
- my $self = bless { apache => $r, cfg => $cfg, output_charset_ok => 0 }, $class;
+ my $self = bless { apache => $r, output_charset_ok => 0 }, $class;
+
+ $self->get_config($r);
- if (my $alternate = $cfg->{ConfigReader} || $r->dir_config('AxConfigReader')) {
- AxKit::reconsecrate($self, $alternate);
+ if (my $alternate = $self->{cfg}->{ConfigReader} || $r->dir_config('AxConfigReader')) {
+ if ($alternate ne __PACKAGE__) {
+ AxKit::reconsecrate($self, $alternate);
+ # re-get config if different package
+ $self->get_config($r);
+ }
}
return $self;
+}
+
+# you may want to override this in your subclass if you write your own ConfigReader
+sub get_config {
+ my $self = shift;
+ $self->{cfg} = _get_config($self->{apache});
}
# sub DESTROY {