Skip to content

Instantly share code, notes, and snippets.

@remorse
Last active March 8, 2017 18:42
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 remorse/f59c149c52b805874cb473bf4a39b6ac to your computer and use it in GitHub Desktop.
Save remorse/f59c149c52b805874cb473bf4a39b6ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
my %p = (:date-gmt("XXX"), :id("XXX"), :slug("XXX"), :tags($["Galaxy", "Galaxy fan render", "planet"]), :type("photo"), :url("http://XXX"), :url-with-slug("http://XXX"));
my %post = (
'_post' => %p,
'_type' => %p{'type'},
'post_id' => %p{'id'},
'post_slug' => %p{'slug'} || %p{'type'},
'post_url' => %p{'url-with-slug'} || %p{'url'},
'post_date' => %p{'date-gmt'},
'post_tags' => '',
'post_body' => '',
);
# fix tags -- doesn't work
if (%p<tags>) {
%post{'post_tags'} = { 'tags' => [] };
for %p{'tags'} -> $tag {
%post{'post_tags'}{'tags'}.push( { 'tag' => $tag });
}
}
say %post.perl;
# if instead of `for %p{'tags'} -> $tag`, I do `for %p{'tags'}:v -> $tag`, it does work.
# perl 5 version:
# fix tags
# if ( scalar( $p->{'tags'} ) ) {
# $post->{'post_tags'} = { 'tags' => [] };
# foreach my $tag ( $p->{'tags'}->@* ) {
# push $post->{'post_tags'}{'tags'}->@*, {
# 'tag' => $tag,
# };
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment