{"action":"created","comment":{"url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/comments/35342764","id":35342764,"diff_hunk":"@@ -0,0 +1,73 @@\n+#!/usr/bin/perl\n+\n+use strict;\n+use warnings;\n+\n+use File::Basename;\n+use File::Spec::Functions;\n+use Data::Dumper;\n+use Getopt::Long;\n+\n+my ( $threshold, $traversal );\n+my ( $path ) = @ARGV;\n+$path //= '.';\n+\n+GetOptions( 't|threshold=n' => \\$threshold,\n+            'r|traversal=s' => \\$traversal );\n+\n+$threshold //= -1;\n+$traversal //= 'breadth-first';\n+\n+my $data = data_for_path( $path, $threshold, $traversal, sub {\n+    my ( $path, $depth ) = @_;\n+\n+    print \"Adding `$path` at depth $depth\\n\";\n+  }\n+);\n+\n+print 'Found the following directory structure: ', Dumper( $data );\n+\n+sub data_for_path {\n+  my( $path, $threshold, $traversal, $on_entry ) = @_;\n+\n+  my $root = {};\n+  my @queue = [ $path, 0, $root ];\n+\n+  my %ops = ( 'depth-first' => sub { unshift @queue, @_ },\n+              'breadth-first' => sub { push @queue, @_ } );\n+\n+  my $op;\n+  $op = $ops{$traversal} if defined $traversal;\n+  $op //= $ops{'depth-first'};\n+\n+  traverse_path_from_work_queue( \\@queue, $op, $threshold, $on_entry // sub {} );\n+  $root;\n+}\n+\n+sub traverse_path_from_work_queue {\n+  my ( $queue, $add_work, $threshold, $on_entry ) = @_;\n+\n+  while( my $next = shift @$queue ) {\n+    my( $path, $level, $contents ) = @$next;\n+    my $basename = basename( $path );\n+    $on_entry->( $path, $level );\n+\n+    $contents->{$basename} = do {\n+      if ( -f $path or -l $path ) { undef }\n+      else {\n+        my $entries = {};\n+\n+        if ( $level < $threshold or $threshold < 0 ) {\n+          opendir my ( $dh ), $path;\n+\n+          my @paths = map { catfile( $path, $_ ) }\n+            grep { ! /^\\.\\.?\\z/ } readdir $dh;\n+\n+          $add_work->( map { [ $_, $level + 1, $entries ] } @paths );\n+        }","path":"chapter10/red/exercise5.pl","position":67,"original_position":67,"commit_id":"74545a33c619274453c4536ab304d0f08708c30f","original_commit_id":"74545a33c619274453c4536ab304d0f08708c30f","user":{"login":"Utopia1138","id":2646781,"avatar_url":"https://avatars.githubusercontent.com/u/2646781?v=3","gravatar_id":"","url":"https://api.github.com/users/Utopia1138","html_url":"https://github.com/Utopia1138","followers_url":"https://api.github.com/users/Utopia1138/followers","following_url":"https://api.github.com/users/Utopia1138/following{/other_user}","gists_url":"https://api.github.com/users/Utopia1138/gists{/gist_id}","starred_url":"https://api.github.com/users/Utopia1138/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Utopia1138/subscriptions","organizations_url":"https://api.github.com/users/Utopia1138/orgs","repos_url":"https://api.github.com/users/Utopia1138/repos","events_url":"https://api.github.com/users/Utopia1138/events{/privacy}","received_events_url":"https://api.github.com/users/Utopia1138/received_events","type":"User","site_admin":false},"body":"No worries, it's a good thing to be looking out for.","created_at":"2015-07-23T16:42:43Z","updated_at":"2015-07-23T16:42:43Z","html_url":"https://github.com/ardavey/Intermediate-Perl/pull/69#discussion_r35342764","pull_request_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69","_links":{"self":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/comments/35342764"},"html":{"href":"https://github.com/ardavey/Intermediate-Perl/pull/69#discussion_r35342764"},"pull_request":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69"}}},"pull_request":{"url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69","id":40292020,"html_url":"https://github.com/ardavey/Intermediate-Perl/pull/69","diff_url":"https://github.com/ardavey/Intermediate-Perl/pull/69.diff","patch_url":"https://github.com/ardavey/Intermediate-Perl/pull/69.patch","issue_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/69","number":69,"state":"open","locked":false,"title":"Red Chapter 10 exercises","user":{"login":"Utopia1138","id":2646781,"avatar_url":"https://avatars.githubusercontent.com/u/2646781?v=3","gravatar_id":"","url":"https://api.github.com/users/Utopia1138","html_url":"https://github.com/Utopia1138","followers_url":"https://api.github.com/users/Utopia1138/followers","following_url":"https://api.github.com/users/Utopia1138/following{/other_user}","gists_url":"https://api.github.com/users/Utopia1138/gists{/gist_id}","starred_url":"https://api.github.com/users/Utopia1138/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Utopia1138/subscriptions","organizations_url":"https://api.github.com/users/Utopia1138/orgs","repos_url":"https://api.github.com/users/Utopia1138/repos","events_url":"https://api.github.com/users/Utopia1138/events{/privacy}","received_events_url":"https://api.github.com/users/Utopia1138/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-18T13:17:41Z","updated_at":"2015-07-23T16:42:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98cc5d2edfb0a680d84c22d84bad27f29d437a85","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69/commits","review_comments_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69/comments","review_comment_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/69/comments","statuses_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/statuses/74545a33c619274453c4536ab304d0f08708c30f","head":{"label":"ardavey:red_chapter10","ref":"red_chapter10","sha":"74545a33c619274453c4536ab304d0f08708c30f","user":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?v=3","gravatar_id":"","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"repo":{"id":26066281,"name":"Intermediate-Perl","full_name":"ardavey/Intermediate-Perl","owner":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?v=3","gravatar_id":"","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ardavey/Intermediate-Perl","description":"Exercise solutions from the O'Reilly book of the same name.","fork":false,"url":"https://api.github.com/repos/ardavey/Intermediate-Perl","forks_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/forks","keys_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/teams","hooks_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/hooks","issue_events_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/events{/number}","events_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/events","assignees_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/assignees{/user}","branches_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/branches{/branch}","tags_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/tags","blobs_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/refs{/sha}","trees_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/statuses/{sha}","languages_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/languages","stargazers_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/stargazers","contributors_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/contributors","subscribers_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/subscribers","subscription_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/subscription","commits_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/commits{/sha}","git_commits_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/commits{/sha}","comments_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/comments{/number}","issue_comment_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/comments{/number}","contents_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/contents/{+path}","compare_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/merges","archive_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/downloads","issues_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues{/number}","pulls_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls{/number}","milestones_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/milestones{/number}","notifications_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/labels{/name}","releases_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/releases{/id}","created_at":"2014-11-01T23:27:01Z","updated_at":"2015-05-22T09:48:20Z","pushed_at":"2015-07-23T15:47:47Z","git_url":"git://github.com/ardavey/Intermediate-Perl.git","ssh_url":"git@github.com:ardavey/Intermediate-Perl.git","clone_url":"https://github.com/ardavey/Intermediate-Perl.git","svn_url":"https://github.com/ardavey/Intermediate-Perl","homepage":null,"size":4534,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"ardavey:master","ref":"master","sha":"e4b72b667ac16b344a833f910839b8ba371b9d05","user":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?v=3","gravatar_id":"","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"repo":{"id":26066281,"name":"Intermediate-Perl","full_name":"ardavey/Intermediate-Perl","owner":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?v=3","gravatar_id":"","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ardavey/Intermediate-Perl","description":"Exercise solutions from the O'Reilly book of the same name.","fork":false,"url":"https://api.github.com/repos/ardavey/Intermediate-Perl","forks_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/forks","keys_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/teams","hooks_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/hooks","issue_events_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/events{/number}","events_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/events","assignees_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/assignees{/user}","branches_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/branches{/branch}","tags_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/tags","blobs_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/refs{/sha}","trees_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/statuses/{sha}","languages_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/languages","stargazers_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/stargazers","contributors_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/contributors","subscribers_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/subscribers","subscription_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/subscription","commits_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/commits{/sha}","git_commits_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/git/commits{/sha}","comments_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/comments{/number}","issue_comment_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/comments{/number}","contents_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/contents/{+path}","compare_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/merges","archive_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/downloads","issues_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues{/number}","pulls_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls{/number}","milestones_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/milestones{/number}","notifications_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/labels{/name}","releases_url":"https://api.github.com/repos/ardavey/Intermediate-Perl/releases{/id}","created_at":"2014-11-01T23:27:01Z","updated_at":"2015-05-22T09:48:20Z","pushed_at":"2015-07-23T15:47:47Z","git_url":"git://github.com/ardavey/Intermediate-Perl.git","ssh_url":"git@github.com:ardavey/Intermediate-Perl.git","clone_url":"https://github.com/ardavey/Intermediate-Perl.git","svn_url":"https://github.com/ardavey/Intermediate-Perl","homepage":null,"size":4534,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69"},"html":{"href":"https://github.com/ardavey/Intermediate-Perl/pull/69"},"issue":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/69"},"comments":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/ardavey/Intermediate-Perl/statuses/74545a33c619274453c4536ab304d0f08708c30f"}}}}