+ my $result = reduce {
+ [
+ grep { $_ }
+ cross {
+ if ( $a->{to_table} eq $b->{from_table}
+ && $a->{to_id} eq $b->{from_id} ) {
+ +{ from_table => $a->{from_table},
+ from_id => $a->{from_id},
+ to_table => $b->{to_table},
+ to_id => $b->{to_id} }
+ }
+ } @{ $a }, @{ $b }
+ ]
+ } @links;
+