Skip Menu |
Report information
Id: 130709
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cjfields [at] illinois.edu
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: Issue with dynamic loading of module
From: "Fields, Christopher J" <cjfields [...] illinois.edu>
To: "rakudobug [...] perl.org" <rakudobug [...] perl.org>
Date: Fri, 3 Feb 2017 04:40:37 +0000
Download (untitled) / with headers
text/plain 491b
I am running into a bug that seems to have appeared after lexical module loading was fixed:


The stripped-down code (w. tests) is located here:


It appears that attempting to load modules dynamically when they are located deeper in the library (in at least one nested directory) fails with a ‘No symbol found’ error.  Any help appreciated

Thanks,

chris
Download (untitled) / with headers
text/plain 859b
The issue can be worked around/fixed with the following patch: diff --git a/lib/Bio/SeqIO.pm6 b/lib/Bio/SeqIO.pm6 index 9ee4980..710dec4 100644 --- a/lib/Bio/SeqIO.pm6 +++ b/lib/Bio/SeqIO.pm6 @@ -10,10 +10,10 @@ class Bio::SeqIO { require ::($format); }; - if ::($format) ~~ Failure { + if MY::{$format} ~~ Failure { die "Can't load $format: $!"; } else { - $!plugin = ::($format).new(); + $!plugin = MY::{$format}.new(); } } } As the symbols are imported lexically, you will find them in the lexical (MY) scope. I'm not sure if this should be considered a bug or not. I'm not familiar enough with the thoughts that went into the design. It's certainly a pitty, that ::() which is quite short became less useful and users have to use the longer MY::() instead.
Download (untitled) / with headers
text/plain 1.4k
Thanks nine. My suggestion is that it's at the very least a buglet, in that there isn't consistency with how modules are loaded (note the module in the base directory, 'fasta', worked). If the syntax stays, I also think it's worth noting this behavior in the docs and pointing out why it's set up this way, both of the following imply the 'require ::($foo)' should work, but maybe this wasn't worked out prior to lexical module fixes? https://docs.perl6.org/syntax/require https://docs.perl6.org/language/packages#index-entry-%3A%3A%28%29 On Fri, 03 Feb 2017 02:34:45 -0800, nine@detonation.org wrote: Show quoted text
> The issue can be worked around/fixed with the following patch: > > diff --git a/lib/Bio/SeqIO.pm6 b/lib/Bio/SeqIO.pm6 > index 9ee4980..710dec4 100644 > --- a/lib/Bio/SeqIO.pm6 > +++ b/lib/Bio/SeqIO.pm6 > @@ -10,10 +10,10 @@ class Bio::SeqIO { > require ::($format); > }; > > - if ::($format) ~~ Failure { > + if MY::{$format} ~~ Failure { > die "Can't load $format: $!"; > } else { > - $!plugin = ::($format).new(); > + $!plugin = MY::{$format}.new(); > } > } > } > > As the symbols are imported lexically, you will find them in the > lexical (MY) scope. I'm not sure if this should be considered a bug or > not. I'm not familiar enough with the thoughts that went into the > design. It's certainly a pitty, that ::() which is quite short became > less useful and users have to use the longer MY::() instead.
From: "Fields, Christopher J" <cjfields [...] illinois.edu>
Date: Fri, 3 Feb 2017 13:43:27 +0000
Subject: Re: [perl #130709] Issue with dynamic loading of module
To: "perl6-bugs-followup [...] perl.org" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 1.9k
Ah, okay, I missed that it isn’t in the ‘require’ but in the symbol lookup afterwards. Okay, I think this makes some sense (I’ll look through docs to see if it goes with what is mentioned there), though it is a bit inconsistent in behavior with the base ‘fasta' module working while the nested ones (‘Bio::fasta’, ‘Bio::SeqIO::fasta’) don't. On 2/3/17, 7:38 AM, "Chris Fields via RT" <perl6-bugs-followup@perl.org> wrote: Show quoted text
>Thanks nine. My suggestion is that it's at the very least a buglet, in that there isn't consistency with how modules are loaded (note the module in the base directory, 'fasta', worked). > >If the syntax stays, I also think it's worth noting this behavior in the docs and pointing out why it's set up this way, both of the following imply the 'require ::($foo)' should work, but maybe this wasn't worked out prior to lexical module fixes? > >https://docs.perl6.org/syntax/require >https://docs.perl6.org/language/packages#index-entry-%3A%3A%28%29 > >On Fri, 03 Feb 2017 02:34:45 -0800, nine@detonation.org wrote:
>> The issue can be worked around/fixed with the following patch: >> >> diff --git a/lib/Bio/SeqIO.pm6 b/lib/Bio/SeqIO.pm6 >> index 9ee4980..710dec4 100644 >> --- a/lib/Bio/SeqIO.pm6 >> +++ b/lib/Bio/SeqIO.pm6 >> @@ -10,10 +10,10 @@ class Bio::SeqIO { >> require ::($format); >> }; >> >> - if ::($format) ~~ Failure { >> + if MY::{$format} ~~ Failure { >> die "Can't load $format: $!"; >> } else { >> - $!plugin = ::($format).new(); >> + $!plugin = MY::{$format}.new(); >> } >> } >> } >> >> As the symbols are imported lexically, you will find them in the >> lexical (MY) scope. I'm not sure if this should be considered a bug or >> not. I'm not familiar enough with the thoughts that went into the >> design. It's certainly a pitty, that ::() which is quite short became >> less useful and users have to use the longer MY::() instead.
> >
Date: Sat, 04 Feb 2017 13:40:14 +0000
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: Re: [perl #130709] Issue with dynamic loading of module
To: "Fields, Christopher J" <cjfields [...] illinois.edu>, "perl6-bugs-followup [...] perl.org" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 2.4k
looks similar to: https://rt.perl.org/Public/Bug/Display.html?id=130535

require seems to be pretty broken since the lexical module thing. Unfortunately our tests weren't good enough to pick this up ( I think it's because it's being required dynamically outside the mainline).

LL

On Sat, Feb 4, 2017 at 4:32 PM Fields, Christopher J <cjfields@illinois.edu> wrote:
Show quoted text
Ah, okay, I missed that it isn’t in the ‘require’ but in the symbol lookup afterwards.  Okay, I think this makes some sense (I’ll look through docs to see if it goes with what is mentioned there), though it is a bit inconsistent in behavior with the base ‘fasta' module working while the nested ones (‘Bio::fasta’, ‘Bio::SeqIO::fasta’) don't.



On 2/3/17, 7:38 AM, "Chris Fields via RT" <perl6-bugs-followup@perl.org> wrote:

>Thanks nine.  My suggestion is that it's at the very least a buglet, in that there isn't consistency with how modules are loaded (note the module in the base directory, 'fasta', worked).
>
>If the syntax stays, I also think it's worth noting this behavior in the docs and pointing out why it's set up this way, both of the following imply the 'require ::($foo)' should work, but maybe this wasn't worked out prior to lexical module fixes?
>
>https://docs.perl6.org/syntax/require
>https://docs.perl6.org/language/packages#index-entry-%3A%3A%28%29
>
>On Fri, 03 Feb 2017 02:34:45 -0800, nine@detonation.org wrote:
>> The issue can be worked around/fixed with the following patch:
>>
>> diff --git a/lib/Bio/SeqIO.pm6 b/lib/Bio/SeqIO.pm6
>> index 9ee4980..710dec4 100644
>> --- a/lib/Bio/SeqIO.pm6
>> +++ b/lib/Bio/SeqIO.pm6
>> @@ -10,10 +10,10 @@ class Bio::SeqIO {
>>              require ::($format);
>>          };
>>
>> -        if ::($format) ~~ Failure {
>> +        if MY::{$format} ~~ Failure {
>>              die "Can't load $format: $!";
>>          } else {
>> -            $!plugin = ::($format).new();
>> +            $!plugin = MY::{$format}.new();
>>          }
>>      }
>>  }
>>
>> As the symbols are imported lexically, you will find them in the
>> lexical (MY) scope. I'm not sure if this should be considered a bug or
>> not. I'm not familiar enough with the thoughts that went into the
>> design. It's certainly a pitty, that ::() which is quite short became
>> less useful and users have to use the longer MY::() instead.
>
>
From: "Fields, Christopher J" <cjfields [...] illinois.edu>
Subject: Re: [perl #130709] Issue with dynamic loading of module
To: Lloyd Fournier <lloyd.fourn [...] gmail.com>, "perl6-bugs-followup [...] perl.org" <perl6-bugs-followup [...] perl.org>
Date: Sun, 5 Feb 2017 03:10:05 +0000
Download (untitled) / with headers
text/plain 1.2k
nine, I did an update to show that the proposed fix doesn’t actually work.  The tests pass but that’s b/c they aren’t testing for instances of that class; a simple check  of the data indicates that the ‘MY::{$plugin}’ is Nil and the produced object is an Any.

chris

From: Lloyd Fournier <lloyd.fourn@gmail.com>
Date: Saturday, February 4, 2017 at 7:40 AM
To: Chris Fields <cjfields@illinois.edu>, "perl6-bugs-followup@perl.org" <perl6-bugs-followup@perl.org>
Subject: Re: [perl #130709] Issue with dynamic loading of module

Show quoted text
looks similar to: https://rt.perl.org/Public/Bug/Display.html?id=130535

require seems to be pretty broken since the lexical module thing. Unfortunately our tests weren't good enough to pick this up ( I think it's because it's being required dynamically outside the mainline).

LL



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org