Author: spadkins
Date: Mon Mar 12 12:54:53 2007
New Revision: 9229
Modified:
p5ee/trunk/App-Context/lib/App/Service.pm
Log:
enhance dump() method
Modified: p5ee/trunk/App-Context/lib/App/Service.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Service.pm (original)
+++ p5ee/trunk/App-Context/lib/App/Service.pm Mon Mar 12 12:54:53 2007
@@ -258,11 +258,50 @@
use Data::Dumper;
sub dump {
- my ($self) = @_;
- my %copy = %$self;
- delete $copy{context}; # don't dump the reference to the context itself
- my $name = $self->service_type() . "__" . $self->{name};
- my $d = Data::Dumper->new([ \%copy ], [ $name ]);
+ 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();
}
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.