in reply to Safe.pm, Barcode::DataMatrix, Can't locate object method "new" via package "Barcode::DataMatrix"

Are you *sure* this is the code you're running? When I run it, I get "Not a coderef" (after installing Barcode::DataMatrix)

That error is caused either when you call a legit method on a class/object, but you haven't use Barcode::DataMatrix; (but you have), or you've loaded the module, but the method doesn't exist (in this case it does). This is often caused by a typo... like typing new() as nw() by accident.

Test this yourself with this tiny sample and see what happens...

use strict; use warnings; use Barcode::DataMatrix; use Safe; my $mat = Barcode::DataMatrix->new()->barcode( 1 ); print $mat;

You should get similar output to this:

$ ./bc.pl ARRAY(0x1960758)
  • Comment on Re: Safe.pm, Barcode::DataMatrix, Can't locate object method "new" via package "Barcode::DataMatrix"
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Safe.pm, Barcode::DataMatrix, Can't locate object method "new" via package "Barcode::DataMatrix"
by Tharg (Scribe) on Jul 19, 2015 at 14:56 UTC
    Yeah, I just copy / pasted it direct from here again and re-tested :
    C:\Users\XX\TestSafe>perl TestSafe.pl (in cleanup) Can't locate object method "new" via package "Bar +code::DataMatrix" (perhaps you forgot to load "Barcode::DataMatrix"?) + at TestSafe.pl line 13. Failed
    This 'snippet' is just a stripped-down-for-posting version of the actual code, but it gives me the same error.
      at TestSafe.pl line 13
      That seems to be the error from your own code - have you tested the sample code that stevieb gave you?
        I have now (it was just edited in I think) :
        C:\Users\XX\TestSafe>teststeve.pl ARRAY(0x37c520) C:\Users\XX\TestSafe>
        My function DataMatrix2d works fine outside of the safe compartment. (Note the last several lines of my code above don't make that much sense - I'm testing the wrong stuff after the code ref check, but my problem comes before then)
Re^2: Safe.pm, Barcode::DataMatrix, Can't locate object method "new" via package "Barcode::DataMatrix"
by Tharg (Scribe) on Jul 19, 2015 at 15:31 UTC
    Yeah that's what I get if I don't use the safe compartment (using your code) ... :
    C:\Users\XX\TestSafe>teststeve.pl ARRAY(0x37c520) C:\Users\XX\TestSafe>
    Using my DataMatrix2d function without putting it in a string and using reval on it etc. :
    C:\Users\XX\TestSafe>perl TestFunc.pl ARRAY(0x51c520) C:\Users\XX\TestSafe>