cbanker has asked for the wisdom of the Perl Monks concerning the following question:

I'm having an odd issue when using the Digest::SHA::PurePerl module on an ARM chip using microperl 5.8.6. I made up a very basic test script to test the module:
#!/usr/bin/perl use Digest::SHA::PurePerl; my $shaVal = Digest::SHA::PurePerl::sha256('test'); print "SHA value: ", $shaVal, "\n";
On an i686 linux system (also testing with microperl 5.8.6 and same libs), I get valid output. However, on the ARM system, I get the following error:
Undefined subroutine &Digest::SHA::PurePerl::sha256 called at ./test.p +l line 5.
The PurePerl.pm module is a slightly modified version, in which I removed the use of FileHandle.pm by omitting the ancillary dump / load functions to avoid using modules that require dynamic loading. However, this same modified module is used on both test systems. Does anyone have any idea what might be going on here? My suspicion is that it has to do with how the SHA module determines the functions to use based on the function name (i.e. there is no actual sub called sha256), but I can't figure out what that would be a problem just because of the different architecture. Any help or suggestions for fixes would be greatly appreciated.

Replies are listed 'Best First'.
Re: Undefined subroutine on ARM but not i686
by ikegami (Patriarch) on Jun 01, 2009 at 22:08 UTC
    Out of curiosity, what do you get from adding
    print "$_\n" for @Digest::SHA::PurePerl::EXPORT_OK;

    There's nothing conditional in building the subs, so I don't see how sha256 could be missing.

    Try changing
    eval($fcn);
    to
    eval("$fcn; 1") or die $@;

      Here's the output I get from that command:
      hmac_sha1 hmac_sha1_base64 hmac_sha1_hex hmac_sha224 hmac_sha224_base64 hmac_sha224_hex hmac_sha256 hmac_sha256_base64 hmac_sha256_hex hmac_sha384 hmac_sha384_base64 hmac_sha384_hex hmac_sha512 hmac_sha512_base64 hmac_sha512_hex sha1 sha1_base64 sha1_hex sha224 sha224_base64 sha224_hex sha256 sha256_base64 sha256_hex sha384 sha384_base64 sha384_hex sha512 sha512_base64 sha512_hex
      For the second part, assuming you meant to change the code like this:
      #!/usr/bin/perl use Digest::SHA::PurePerl; my $shad = eval("Digest::SHA::PurePerl::sha256('test');1") or die $@; print "SHA value: ", $shad, "\n";
      Here's the output I get:
      Undefined subroutine &Digest::SHA::PurePerl::sha256 called at (eval 3) + line 1.
      As far as I can tell those outputs don't seem to show anything too valuable other than the fact that the exports are there. Any other ideas?
        For the second part,...

        I think he meant the place in PurePerl.pm, where @EXPORT_OK is being populated (line 774):

        eval($fcn); push(@EXPORT_OK, 'sha' . $alg . $suffix_extern[$i]);

        This would allow you to see if/how the eval failed...

Re: Undefined subroutine on ARM but not i686 ($@)
by tye (Sage) on Jun 02, 2009 at 01:14 UTC

    That could certainly happen if the line:

    eval($fcn);

    failed. It is unfortunate that the module just ignores whether that fails or not. Each of those lines should be changed, for example, to:

    eval("$fcn; 1") or die $@;

    Doing that in your modified version of the module might give you a hint as to why it isn't working.

    - tye        

      Asked and answered. The eval doesn't even get executed since @EXPORT_OK doesn't get populated.