Hi Monks, Given 'mylib/json.pm':
package mylib::json; use Exporter 'import'; our @EXPORT=qw(jsonEncode); use JSON::XS; sub jsonEncode($) { my ($o) = @_; my $j = undef; eval { $j = JSON::XS->new->encode($o); }; return $@ ? undef : $j; }
And 'mylib.pm':
package mylib; use Exporter 'import'; use lib 'mylib'; use mylib::json; our @EXPORT = ( @mylib::json::EXPORT );
Then the following 'test.pl' works fine:
use strict; use warnings; use lib '.'; use mylib; print jsonEncode({foo => 'bar'});
However once I add 'use JSON::WebToken' module I get an issue:
use strict; use warnings; use lib '.'; use mylib; use JSON::WebToken; print jsonEncode({foo => 'bar'});

This warns:

Attempt to call undefined import method with arguments ("encode_json" +...) via package "JSON" (Perhaps you forgot to load the package?) at +C:/Strawberry/perl/site/lib/JSON/WebToken.pm line 12.

I don't understand what I am doing with mylib that impacts what JSON::WebToken does? Without mylib JSON::WebToken is working fine.


In reply to Undefined import name priority issue? by sectokia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.