commit: b77528ed7f76611ffc8ef115d53f05b54040edba
parent: 22dc9b867e10ff2c56891561e59517542a4ffba4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 5 May 2020 23:02:24 +0200
ap-represent.pl: DRY on textual keys
Diffstat:
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/ap-represent.pl b/ap-represent.pl
@@ -9,6 +9,14 @@ use Data::Dumper;
my $json = JSON::MaybeXS->new(utf8 => 1, pretty => 1);
+sub print_object_key {
+ my ($indent, $object, $key) = @_;
+
+ if(exists $object->{$key}) {
+ printf "%*s%s: %s\n", $indent, ' ', $key, $object->{$key};
+ }
+}
+
sub print_object {
my ($indent, $object) = @_;
@@ -17,16 +25,9 @@ sub print_object {
printf ' ā%sā', $object->{"name"} if $object->{"name"};
printf ' @%s', $object->{"preferredUsername"} if $object->{"preferredUsername"};
print "\n";
- printf "%*sURL: <%s>\n", $indent, ' ', $object->{"url"} if $object->{"url"};
- printf "%*sContext: %s\n", $indent, ' ', $object->{"context"} if $object->{"context"};
- printf "%*sInbox: <%s>\n", $indent, ' ', $object->{"inbox"} if $object->{"inbox"};
- printf "%*sOutbox: <%s>\n", $indent, ' ', $object->{"outbox"} if $object->{"outbox"};
- printf "%*sPrevious Page: <%s>\n", $indent, ' ', $object->{"prev"} if $object->{"prev"};
- printf "%*sNext Page: <%s>\n", $indent, ' ', $object->{"next"} if $object->{"next"};
- printf "%*sPublished: %s\n", $indent, ' ', $object->{"published"} if $object->{"published"};
- printf "%*sUpdated: %s\n", $indent, ' ', $object->{"updated"} if $object->{"updated"};
- printf "%*sSummary: %s\n", $indent, ' ', $object->{"summary"} if $object->{"summary"};
- printf "%*sContent: %s\n", $indent, ' ', $object->{"content"} if $object->{"content"};
+ foreach("url", "context", "inbox", "outbox", "prev", "next", "published", "updated", "summary", "content") {
+ print_object_key($indent, $object, $_);
+ }
if(exists $object->{"object"}) {
printf "%*sobject: ", $indent, ' ';
print_ref($indent+4, $object->{"object"});