title: Internal State Changes After try{} Block
body: <p>I'm working with <a href="https://metacpan.org/module/JKEGL/Marpa-R2-2.058000/pod/Marpa_R2.pod" rel="nofollow">Marpa::R2</a>, and am trying to catch errors using <a href="https://metacpan.org/module/Try%3a%3aTiny" rel="nofollow">Try::Tiny</a>. I am puzzled because when I put the parsing code into a <code>try</code> block, the result of the <code>value</code> method is <code>undef</code>. Here's my code:</p>
  
  <pre><code>use strict;
  use warnings;
  use Marpa::R2;
  use Data::Dumper;
  use Try::Tiny;
  
  my $grammar = Marpa::R2::Scanless::G-&gt;new(
      {
          source =&gt; \(&lt;&lt;'END_OF_SOURCE'),
              :default ::= action =&gt; ::array
              :discard ~ ws
              ws ~ [\s]+
              :start ::= Name
              Name ::= Foo
              Foo ~ [\w]+
  END_OF_SOURCE
      }
  );
  my $reader = Marpa::R2::Scanless::R-&gt;new(
      {
          grammar =&gt; $grammar,
      }
  );
  my $input = 'foo';
  try{
      $reader-&gt;read(\$input);
  }catch {
      warn "caught error: $_";
  }
  my $value = $reader-&gt;value;
  print Dumper $value;
  </code></pre>
  
  <p>I was going a little nuts trying to figure out what was the grammar, and then I realized that removing the <code>try</code> block made the value of <code>$reader-&gt;value</code> non-null. Even if I assign <code>$value</code> within the <code>try</code> block, it becomes <code>undef</code> when the block is finished:</p>
  
  <pre><code>my $value;
  try{
      $reader-&gt;read(\$input);
      $value = $reader-&gt;value;
  }catch {
      warn "caught error: $_";
  }
  print Dumper $value;
  </code></pre>
  
  <p>This seems to mean that if I want to catch errors with <code>Try::Tiny</code>, I have to put ALL of my processing of <code>$value</code> into the <code>try</code> block, which is inconvenient.</p>
  
  <p>Can anyone tell me what is causing this (I'd like an explanation of how this is possible in Perl)? And is there a way to fix it?</p>