commit: bab23c34d81b6d0e399176b8a68ab5108dc965ae
parent: 0af5d1accd368b668fc89d1038d9cb3fded854cd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 6 May 2020 01:01:12 +0200
ap-represent.pl: Add support for bcc, bto, cc, …
Diffstat:
1 file changed, 19 insertions(+), 30 deletions(-)
diff --git a/ap-represent.pl b/ap-represent.pl
@@ -7,61 +7,49 @@ use Scalar::Util qw(reftype);
use JSON::MaybeXS;
use Data::Dumper;
-my $json = JSON::MaybeXS->new(utf8 => 1, pretty => 1);
+my $json = JSON::MaybeXS->new(utf8 => 1);
sub print_object_key {
my ($indent, $object, $key) = @_;
- if(exists $object->{$key}) {
- printf "%*s%s: %s\n", $indent, ' ', $key, $object->{$key};
+ if($object->{$key}) {
+ print_ref($indent, $object->{$key}, $key);
}
}
sub print_object {
my ($indent, $object) = @_;
- printf '%*s %s', $indent, "⇒", $object->{"type"};
+ printf "%*s %s", $indent, '⇒', $object->{"type"};
printf ' <%s>', $object->{"id"} if $object->{"id"};
printf ' “%s”', $object->{"name"} if $object->{"name"};
printf ' @%s', $object->{"preferredUsername"} if $object->{"preferredUsername"};
printf ' ⚠' if ($object->{"sensitive"} eq JSON->true);
- print "\n";
- foreach("url", "context", "inbox", "outbox", "prev", "next", "published", "updated", "summary", "content") {
+ foreach("url", "context", "inbox", "outbox", "prev", "next", "published", "updated", "summary", "content", "bcc", "bto", "to", "cc", "object", "attachment", "tag", "orderedItems") {
print_object_key($indent, $object, $_);
}
- if(exists $object->{"object"}) {
- printf "%*sobject: ", $indent, ' ';
- print_ref($indent+4, $object->{"object"});
- }
- if(exists $object->{"attachment"}) {
- printf "%*sattachment: ", $indent, ' ';
- print_ref($indent+4, $object->{"attachment"});
- }
- if(exists $object->{"tag"}) {
- printf "%*stag: ", $indent, ' ';
- print_ref($indent+4, $object->{"tag"});
- }
- if(exists $object->{"orderedItems"}) {
- printf "%*sorderedItems: ", $indent, ' ';
- print_ref($indent+4, $object->{"orderedItems"});
- }
}
sub print_ref {
- my ($indent, $object) = @_;
+ my ($indent, $object, $name) = @_;
my $ref_type = reftype($object);
- if($ref_type eq "HASH") {
- print "\n";
- print_object($indent, $object);
- } elsif($ref_type eq "ARRAY") {
- print "\n";
+ if($ref_type eq 'HASH') {
+ printf "\n%*s%s: \n", $indent, ' ', $name;
+ print_object($indent+4, $object);
+ } elsif($ref_type eq 'ARRAY') {
+ printf "\n%*s%s: ", $indent, ' ', $name if @{$object};
foreach(@{$object}) {
- print_object($indent, $_);
+ if(reftype($_) eq 'HASH') {
+ print "\n";
+ print_object($indent+4, $_);
+ } else {
+ printf "%s ; ", $_;
+ }
}
} else {
- print $object, "\n";
+ printf "\n%*s%s: %s", $indent, ' ', $name, $object;
}
}
@@ -72,3 +60,4 @@ my $blob;
}
print_object(1, $blob);
+print "\n";