There's nothing like a bit of self inflicted public shaming.

Today I had a case of the magically missing data structure. We have a bit of code that's very hard to test with automated testing, and that part of the code died at an important point in time. Pending the refactor guy getting onto the root cause I came up with this nice snippet. At the time I said "this is the kind of code that you're simultaneously proud of and ashamed of". So I figured I'd put it here as a bit of public shaming.

@@ -61,6 +63,16 @@ sub _do_create_jobqueue_data {
     elsif ($self->content->can('frontend_output')) {
-        my $thing = $self->content->frontend_output
-            ?  $self->content->frontend_output->driver_info()
+
+        use Data::Walk; # provides walkdepth, takes callback to examine each
+                        # node of data strucutre and data the data structure
+                        # to be examined
+        my frontend_output;
+        walkdepth ( sub {
+            $frontend_output = $_ if $_->isa('MyApp::Model::FrontEndOutput');
+        }
+            , $self->content);
+
+        my $things = $frontend_output
+            ?  $frontend_output->driver_info()
                 : {};
     if (exists $things->{metadata}) {

Leave a comment

About kd

user-pic Australian perl hacker.