sectokia has asked for the wisdom of the Perl Monks concerning the following question:
And 'mylib.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; }
Then the following 'test.pl' works fine:package mylib; use Exporter 'import'; use lib 'mylib'; use mylib::json; our @EXPORT = ( @mylib::json::EXPORT );
However once I add 'use JSON::WebToken' module I get an issue:use strict; use warnings; use lib '.'; use mylib; print jsonEncode({foo => 'bar'});
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Undefined import name priority issue?
by hv (Prior) on Apr 08, 2025 at 03:00 UTC | |
by sectokia (Friar) on Apr 08, 2025 at 03:31 UTC | |
by afoken (Chancellor) on Apr 08, 2025 at 08:05 UTC | |
by sectokia (Friar) on Apr 08, 2025 at 21:56 UTC | |
by ikegami (Patriarch) on Apr 09, 2025 at 02:25 UTC | |
by hippo (Archbishop) on Apr 08, 2025 at 08:06 UTC |