title: Unblessed reference in Perl
body: <p>I have a Perl application that use mode <code>WWW::Scripter</code>. It parse very huge codes and all works great, just one problem occurs that I cannot understand.</p>
  
  <p>I am getting error</p>
  
  <p><strong>Can't call method "addEventListener" on unblessed reference 
        at /usr/lib/perl5/site_perl/5.8.8/JE.pm line ...</strong></p>
  
  <p>It looks like an error in <code>JE.pm</code> (JavaScript Engine), which seems to be stable. This JE is called from <code>WWW::Scripter</code>, which seems to be also stable module.</p>
  
  <p>Tracking JavaScript source I realized, that such error sometimes (not always) happens on the following part of JavaScript:</p>
  
  <pre><code>var addEvent=(function(){if(document.addEventListener){...
  </code></pre>
  
  <p>which seems to be correct as well.</p>
  
  <p>Let's take a look at a section of <code>JE.pm</code>, where the error occurs >></p>
  
  <pre><code>        my ($method, $type) = _split_meth $m;
  
          $proto-&gt;new_method(
            $name =&gt; defined $type
              ? $unwrap
                ? sub {
                  $self-&gt;_cast(
                    scalar shift-&gt;value-&gt;$method(
                      $self-&gt;_unwrap(@_)),
                    $type
                  );
                }
                : sub {
                  $self-&gt;_cast(
                    scalar shift-&gt;value-&gt;$method(@_),
                    $type
                  );
                }
              : $unwrap
                ? sub { shift-&gt;value-&gt;$m(
                  $self-&gt;_unwrap(@_)) }
                : sub { shift-&gt;value-&gt;$m(@_) },
          );
  </code></pre>
  
  <p>and the "line", where such error occurs is its bottom part, so >></p>
  
  <pre><code>            : $unwrap
                ? sub { shift-&gt;value-&gt;$m(
                  $self-&gt;_unwrap(@_)) }
                : sub { shift-&gt;value-&gt;$m(@_) },
  </code></pre>
  
  <p>So what is wrong? What exactly error <strong>unblessed reference</strong> in this case means?</p>