Flickr

use strict;
use warnings;

use Flickr::API;
use Perl6::Say;
use XML::LibXML;

my $key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
my $secret = 'XXXXXXXXXXXXXXXX';

my $id = shift or die;

my $api = Flickr::API->new({
    key => $key,
    secret => $secret,
});

my $res = $api->execute_method('flickr.photos.getSizes', {
    photo_id => $id,
});

my $doc = XML::LibXML->load_xml(string => $res->decoded_content);
#my @nodes = $doc->findnodes('//size');
#
#my @photos;
#foreach my $node (@nodes) {
#    my $width = $node->getAttribute('width');
#    my $source = $node->getAttribute('source');
#    push @photos, {
#        width => $width,
#        source => $source,
#    };
#}
#
#say for map { $_->{source} } sort {$b->{width} <=> $a->{width}} @photos;

say for map  { $_->{source} }
        sort { $b->{width} <=> $a->{width} }
        map  { +{width => $_->getAttribute('width'), source => $_->getAttribute('source')} }
        $doc->findnodes('//size');