title: Perl method to create an error object using bless. Not sure about the inner-workings of this method
body: <p>I received a solution for creating an object which is a hash with 5 keys. But I am not sure how it exactly works.</p>
  
  <p>This is my example of the error library, I only included one error for the purpose of this question.
  ErrorLibrary.pm</p>
  
  <pre><code>package ASC::Builder::ErrorLibrary;
      use constant {
  
          CABLING_ERROR =&gt; {
              code =&gt; 561,
              message =&gt; "cabling is not correct at T1.",
              tt =&gt; { template =&gt; 'disabled'},
              fatal =&gt; 1,
              wiki_page =&gt;'http://www.e-solution.com/index.php/ARC/Builder/ErrorCodes/CABLING_ERROR',
          }
      };
  </code></pre>
  
  <p>This is my error file which contains a number of methods; the new() that is use for posting an error. 
  The new method can accept the Error hash which are found in the ErrorLibrary or else it can accept a string which is the old way in which the error message were implemented in the system.</p>
  
  <p>Example:</p>
  
  <pre><code>die ASC::Builder::Error-&gt;new(CABLING_ERROR);
  </code></pre>
  
  <p>Error.pm</p>
  
  <pre><code>package ASC::Builder::Error;
      sub new {
  
          my ($package, $first_param) = (shift, shift);
  
  
          if (ref $first_param eq 'HASH') {
              my %params = @_;
              return bless { message =&gt; $first_param-&gt;{message}, code =&gt; $first_param-&gt;{code}, tt =&gt; $first_param-&gt;{tt}, fatal =&gt; $first_param-&gt;{fatal}, wiki_page =&gt; $first_param-&gt;{wiki_page}, %params}, $package;
          }
          else {
              my %params = @_; 
              return bless {message =&gt; $first_param, %params}, $package;
  
      }   
      }
  </code></pre>
  
  <p>What I want to understand about this new() method is what exactly is happening when I assign each key of the error hash to <code>$first_param</code> an then bless all them. Is it gathering all the attributes together and creating an object out of the attributes by using the bless function?</p>
  
  <p>The Error.pm also contains the following methods which allow the value of each key to be accessed.</p>
  
  <pre><code>package ASC::Builder::Error;
      sub message {
          return $_[0]-&gt;{message};
      }
  
      sub tt {
          return $_[0]-&gt;{tt};
      }
  
      sub code {
          return $_[0]-&gt;{code};
      }
  
      sub fatal {
          return $_[0]-&gt;{fatal};
      }
  
      sub wiki_page {
          return $_[0]-&gt;{wiki_page};
      }
  </code></pre>
  
  <p>But as I said I mainly just want to understand what is exactly happening in the new() method. </p>