App-Context
view release on metacpan or search on metacpan
lib/App/Service.pm view on Meta::CPAN
sub content_type {
&App::sub_entry if ($App::trace);
my $content_type = 'text/plain';
&App::sub_exit($content_type) if ($App::trace);
return($content_type);
}
#############################################################################
# content_description()
#############################################################################
=head2 content_description()
* Signature: $content_description = $service->content_description();
* Param: void
* Return: $content_description string
* Throws: App::Exception
* Since: 0.01
Provide a description of the content which is useful for diagnostic purposes
(such as for the timing log implemented in App::Context::HTTP).
This method can be overridden by an application-specific service such as a
web application user interface widget to provide more useful information
in the description.
Sample Usage:
$content_description = $service->content_description();
=cut
sub content_description {
&App::sub_entry if ($App::trace);
my ($self) = @_;
my $class = ref($self);
my $content_description = "$class($self->{name})";
&App::sub_exit($content_description) if ($App::trace);
return($content_description);
}
#############################################################################
# Method: internals()
#############################################################################
=head2 internals()
* Signature: $guts = $self->internals();
* Param: void
* Return: $guts {}
* Throws: App::Exception
* Since: 0.01
$guts = $so->internals();
App::Reference->print($guts);
print App::Reference->dump($guts), "\n";
Copy the internals of the current SessionObject to a new hash and return
a reference to that hash for debugging purposes. The resulting hash
reference may be printed using Data::Dumper (or App::Reference).
The refe
=cut
sub internals {
&App::sub_entry if ($App::trace);
my ($self) = @_;
my %copy = %$self;
delete $copy{context};
delete $copy{dict};
&App::sub_exit(\%copy) if ($App::trace);
return \%copy;
}
#############################################################################
# dump()
#############################################################################
=head2 dump()
* Signature: $perl = $service->dump();
* Param: void
* Return: $perl text
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$service = $context->repository();
print $service->dump(), "\n";
=cut
use Data::Dumper;
sub dump {
my ($self, $ref) = @_;
my ($copy, $data, $name);
if ($ref) {
if (!ref($ref)) {
$data = $ref;
$name = "scalar";
}
elsif (ref($ref) eq "ARRAY") {
$data = [];
my ($r);
foreach my $d (@$ref) {
$r = ref($d);
if (!$r || $r eq "ARRAY" || $r eq "SCALAR") {
push(@$data, $d);
}
elsif (!$d->{context} && !$d->{_repository}) {
push(@$data, $d);
}
else {
$copy = { %$d };
$copy->{context} = "<removed>" if ($copy->{context}); # don't dump the reference to the context itself (Services)
$copy->{_repository} = "<removed>" if ($copy->{_repository}); # don't dump the reference to the repository (RepositoryObjects)
push(@$data, $copy);
}
}
$data = [ $data ];
$name = "array";
}
else {
$copy = { %$ref };
$copy->{context} = "<removed>" if ($copy->{context}); # don't dump the reference to the context itself (Services)
$copy->{_repository} = "<removed>" if ($copy->{_repository}); # don't dump the reference to the repository (RepositoryObjects)
$data = [ $copy ];
$name = "hash";
}
}
else {
$copy = { %$self };
$copy->{context} = "<removed>" if ($copy->{context}); # don't dump the reference to the context itself (Services)
$copy->{_repository} = "<removed>" if ($copy->{_repository}); # don't dump the reference to the repository (RepositoryObjects)
$data = [ $copy ];
$name = $self->service_type() . "__" . $self->{name};
}
my $d = Data::Dumper->new($data, [ $name ]);
$d->Indent(1);
return $d->Dump();
}
#############################################################################
# print()
#############################################################################
=head2 print()
* Signature: $service->print();
* Param: void
* Return: void
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$service->print();
=cut
sub print {
my $self = shift;
print $self->dump();
}
#############################################################################
# substitute()
#############################################################################
=head2 substitute()
* Signature: $result = $service->substitute($target);
* Signature: $result = $service->substitute($target, $values);
* Param: $target HASH,string
* Param: $values HASH
* Return: $result string
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$welcome_message = $service->substitute("Welcome, {default-user}");
my $auto_params = { user => "{default-user}", org_id => "{org_id}", };
my $auto_values = { org_id => 1, };
$params = $service->substitute($auto_params, $auto_values);
The substitute() method scans the $target string (or hash of strings) for
instances of variables (i.e. "{varname}") and makes substitutions.
It makes substitutions from a hash of $values if provided or from the
values of SessionObjects of the same name.
The substitute() method returns a string (or hash of strings) which is the
result of the substitution.
=cut
sub substitute {
( run in 0.843 second using v1.01-cache-2.11-cpan-39bf76dae61 )