Skip to content

Commit

Permalink
split into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gbicann committed Jul 26, 2024
1 parent 1190d2e commit 7275306
Showing 1 changed file with 59 additions and 41 deletions.
100 changes: 59 additions & 41 deletions lib/App/rdapper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ sub main {

} elsif ('tld' eq $type) {
$response = $rdap->fetch(URI->new(IANA_BASE_URL.'domain/'.$object), %args);

} elsif ('url' eq $type) {
my $uri = URI->new($object);

Expand Down Expand Up @@ -428,52 +428,70 @@ sub print_entity {

my $jcard = $entity->jcard;
if ($jcard) {
foreach my $type (@VCARD_DISPLAY_ORDER) {
foreach my $property (grep { $_->value } $jcard->properties($type)) {
if ('ADR' eq $type) {
$package->print_kv('Address', '', $indent);

if ($property->param('label')) {
$out->print(wrap(
INDENT x ($indent + 1),
INDENT x ($indent + 1),
$property->param('label'),
)."\n");

} else {
foreach my $i (@ADR_DISPLAY_ORDER) {
if ($property->value->[$i]) {
if ('ARRAY' eq ref($property->value->[$i])) {
foreach my $v (grep { $_ } @{$property->value->[$i]}) {
$package->print_kv($ADR_DISPLAY_NAMES{$i}, $v, $indent+1);
}

} else {
$package->print_kv($ADR_DISPLAY_NAMES{$i}, $property->value->[$i], $indent+1);

}
}
}
}
$package->print_jcard($jcard, $indent);
}
}

} else {
my $label = $VCARD_NODE_NAMES{$type} || ucfirst(lc($type));
sub print_jcard {
my ($package, $jcard, $indent) = @_;

foreach my $ptype (@VCARD_DISPLAY_ORDER) {
foreach my $property (grep { $_->value } $jcard->properties($ptype)) {
$package->print_jcard_property($property, $indent);
}
}
}

if ('TEL' eq $type) {
if (any { 'fax' eq lc($_) } @{$property->param('type')}) {
$label = 'Fax';
sub print_jcard_property {
my ($package, $property, $indent) = @_;

} else {
$label = 'Phone';
if ('ADR' eq uc($property->type)) {
$package->print_jcard_adr($property, $indent);

} else {
my $label = $VCARD_NODE_NAMES{$property->type} || ucfirst(lc($property->type));

if ('TEL' eq uc($property->type)) {
if (any { 'fax' eq lc($_) } @{$property->param('type')}) {
$label = 'Fax';

} else {
$label = 'Phone';

}
}
}

$package->print_kv(
$label,
'uri' eq $property->value_type ? u($property->value) : $property->value,
$indent
);
}
}

sub print_jcard_adr {
my ($package, $property, $indent) = @_;

$package->print_kv('Address', '', $indent);

if ($property->param('label')) {
$out->print(wrap(
INDENT x ($indent + 1),
INDENT x ($indent + 1),
$property->param('label'),
)."\n");

} else {
foreach my $i (@ADR_DISPLAY_ORDER) {
if ($property->value->[$i]) {
if ('ARRAY' eq ref($property->value->[$i])) {
foreach my $v (grep { $_ } @{$property->value->[$i]}) {
$package->print_kv($ADR_DISPLAY_NAMES{$i}, $v, $indent+1);
}

$package->print_kv(
$label,
'uri' eq $property->value_type ? u($property->value) : $property->value,
$indent
);
} else {
$package->print_kv($ADR_DISPLAY_NAMES{$i}, $property->value->[$i], $indent+1);

}
}
}
Expand Down

0 comments on commit 7275306

Please sign in to comment.