Skip to content

Instantly share code, notes, and snippets.

@btrott
Created November 17, 2009 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btrott/236452 to your computer and use it in GitHub Desktop.
Save btrott/236452 to your computer and use it in GitHub Desktop.
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