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
@[EMAIL PROTECTED]
-459,37 +459,71 @[EMAIL PROTECTED]
$session = $self->{session};
$service = $session->{cache}{$type}{$name}; # check the cache
+ $conf = $self->{conf};
+ $service_conf = $conf->{$type}{$name};
+ my $tem****ary = $args->{tem****ary};
+ 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 (@[EMAIL PROTECTED]
);
+ my $include_files = $service_conf->{include};
+ if (ref($include_files) eq "ARRAY") {
+ @[EMAIL PROTECTED]
= @[EMAIL PROTECTED]
}
+ elsif (ref($include_files) eq "") {
+ @[EMAIL PROTECTED]
= ( $include_files );
+ }
+ foreach my $conf_file (@[EMAIL PROTECTED]
) {
+ $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 $tem****ary = $args->{tem****ary};
# NEVER DEFINED OR NON-BLESSED HASH (fully defined services
are blessed into cl*****)
if ($tem****ary || !defined $service || ref($service) eq "HASH") {
@[EMAIL PROTECTED]
-851,6 +885,60 @[EMAIL PROTECTED]
}
#############################################################################
+# 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) =
@[EMAIL PROTECTED]
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()
#############################################################################


|