Skip to content

Instantly share code, notes, and snippets.

@btrott btrott/gist:236452
Created Nov 17, 2009

Embed
What would you like to do?
sub get_best_avatar_uri {
my $class = shift;
my( $links ) = @_;
return unless $links && @$links;
# Look first for a 50px width avatar...
my $link = first { $_->{rel} eq 'avatar' && $_->{width} == 50 } @$links;
# ... and if we can't find one, grab the largest available avatar,
# which will by definition be less than 50px width, I think?
unless ( $link ) {
$link = reduce { $a->{width} > $b->{width} ? $a : $b }
grep { $_->{rel} eq 'avatar' } @$links;
}
return $link ? $link->{href} : undef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.