Author: spadkins
Date: Tue Jun 26 08:29:24 2007
New Revision: 9682
Modified:
p5ee/trunk/App-Context/lib/App/Context.pm
Log:
added conf file includes and service clones
Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm (original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm Tue Jun 26 08:29:24 2007
@@ -459,37 +459,71 @@
$session = $self->{session};
$service = $session->{cache}{$type}{$name}; # check the cache
+ $conf = $self->{conf};
+ $service_conf = $conf->{$type}{$name};
+ my $temporary = $args->{temporary};
+ my $service_initialized = ($service && ref($service) ne "HASH");
##############################################################
# Load extra conf on demand
##############################################################
- $conf = $self->{conf};
- $service_conf = $conf->{$type}{$name};
- if (!$service_conf) {
+ if (!$service_initialized && !$service_conf && $name !~ /-/) { # if it's not a contained widget, try the file system
my $options = $self->{options};
my $prefix = $options->{prefix};
my $conf_type = $options->{conf_type} || "pl";
my $conf_file = "$prefix/etc/app/$type.$name.$conf_type";
- if (-r $conf_file) {
- $service_conf = App::Conf::File->create({ conf_file => $conf_file });
- $conf->{$type}{$name} = $service_conf;
+ if (!$self->{conf_included}{$conf_file} && -r $conf_file) {
+ my $aux_conf = App::Conf::File->create({ conf_file => $conf_file });
+ $conf->overlay($aux_conf);
+ $service_conf = $conf->{$type}{$name};
}
+ $self->{conf_included}{$conf_file} = 1;
}
##############################################################
# aliases
##############################################################
- if (defined $service_conf) {
+ if (!$service_initialized && $service_conf) {
my $alias = $service_conf->{alias};
if ($alias) {
$name = $alias;
$service = $session->{cache}{$type}{$name};
$service_conf = $conf->{$type}{$name};
}
+ elsif ($type ne "Authorization" && ($service_conf->{clone} || $service_conf->{auth_clone})) {
+ my $clone = $self->get_auth_attrib_value($service_conf, $type, $name, "clone");
+ if ($clone) {
+ $service_conf = $conf->{$type}{$clone};
+ }
+ }
+ }
+
+ ##############################################################
+ # conf includes
+ ##############################################################
+ if (!$service_initialized && $service_conf && $service_conf->{include}) {
+ my $options = $self->{options};
+ my $prefix = $options->{prefix};
+ my (@include_files);
+ my $include_files = $service_conf->{include};
+ if (ref($include_files) eq "ARRAY") {
+ @include_files = @$include_files;
+ }
+ elsif (ref($include_files) eq "") {
+ @include_files = ( $include_files );
+ }
+ foreach my $conf_file (@include_files) {
+ $conf_file = "$prefix/etc/app/$conf_file" if ($conf_file !~ m!^/!);
+ next if ($self->{conf_included}{$conf_file});
+ if (-r $conf_file) {
+ my $aux_conf = App::Conf::File->create({ conf_file => $conf_file });
+ $conf->overlay($aux_conf);
+ }
+ $self->{conf_included}{$conf_file} = 1;
+ }
}
$new_service = 0;
- my $temporary = $args->{temporary};
# NEVER DEFINED OR NON-BLESSED HASH (fully defined services are blessed into classes)
if ($temporary || !defined $service || ref($service) eq "HASH") {
@@ -851,6 +885,60 @@
}
#############################################################################
+# get_auth_attrib_value()
+#############################################################################
+
+=head2 get_auth_attrib_value()
+
+The get_auth_attrib_value() consults the "default" Authorization service to determine
+the "authorized" value of a service configuration's attribute.
+
+ * Signature: $attrib_value = $self->get_auth_attrib_value($service_conf, $service_type, $service_name, $attrib);
+ * Param: $service_conf HASH
+ * Param: $service_type string
+ * Param: $service_name string
+ * Param: $attrib string
+ * Return: $attrib_value ANY
+ * Throws: <none>
+ * Since: 0.01
+
+ Sample Usage:
+
+ $service_type = "SessionObject";
+ $service_name = "foo";
+ $service_conf = $self->{conf}{$service_type}{$service_name};
+ $clone_name = $self->get_auth_attrib_value($service_conf, $service_type, $service_name, "clone");
+
+=cut
+
+sub get_auth_attrib_value {
+ my ($self, $service_conf, $service_type, $service_name, $attrib) = @_;
+ my ($auth_value);
+ my $auth_value_list = $service_conf->{"auth_$attrib"};
+ if ($auth_value_list && ref($auth_value_list) eq "ARRAY") {
+ my ($auth_key, $auth_name);
+ my $auth = $self->authorization();
+ for (my $i = 0; $i <= $#$auth_value_list; $i += 2) {
+ $auth_name = $auth_value_list->[$i];
+ if ($auth_name =~ m!^/!) {
+ $auth_key = $auth_name;
+ }
+ else {
+ $auth_key = "/App/$service_type/$service_name/$auth_name";
+ }
+ if ($auth->is_authorized($auth_key)) {
+ $auth_value = $auth_value_list->[$i+1];
+ last;
+ }
+ }
+ }
+ if (!$auth_value) {
+ $auth_value = $service_conf->{$attrib};
+ }
+ return($auth_value);
+}
+
+#############################################################################
# so_get()
#############################################################################
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.