Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the limitations and work arounds of -e. #250

Open
Caldrin opened this issue Mar 27, 2013 · 1 comment
Open

Document the limitations and work arounds of -e. #250

Caldrin opened this issue Mar 27, 2013 · 1 comment

Comments

@Caldrin
Copy link

Caldrin commented Mar 27, 2013

According to the documentation I expect the func keyword to work like this:
perl -e 'use perl5i::2; func test($t) { return $t } print test("test")'

This gives the following error message:
PL_linestr not long enough, was Devel::Declare loaded soon enough in -e at /home/user/perl5/perls/perl-5.16.2/lib/site_perl/5.16.2/x86_64-linux/Devel/Declare/Context/Simple.pm line 71.

When I use the perl5i binary instead of perl like this:
perl5i -e'use perl5i::2; func test($t) { return $t } print test("test")'

I get
Prototype mismatch: sub main::open (*;$@) vs none at /home/user/perl5/perls/perl-5.16.2/lib/site_perl/5.16.2/perl5i/2/UNIVERSAL.pm line 23
test

Only when I use perl5i and remove the "use perli5::2" inside it works as expected.

@schwern
Copy link
Contributor

schwern commented Mar 28, 2013

Thanks for the report.

The PL_linestr error is an unfortunate bug in Devel::Declare which perl5i uses to rewrite Perl syntax. The same problem appears in related modules like Method::Signatures or MooseX::Method::Signatures.

$ perl -e 'use MooseX::Method::Signatures; method test($t) { return $t } print main->test("test")'
PL_linestr not long enough, was Devel::Declare loaded soon enough in -e at /Users/schwern/perl5/perlbrew/perls/perl-5.16.2-threads/lib/site_perl/5.16.2/darwin-thread-multi-2level/Devel/Declare/Context/Simple.pm line 71.

$ perl -e 'use Method::Signatures; method test($t) { return $t } print main->test("test")'
PL_linestr not long enough, was Devel::Declare loaded soon enough in -e at /Users/schwern/perl5/perlbrew/perls/perl-5.16.2-threads/lib/site_perl/5.16.2/darwin-thread-multi-2level/Devel/Declare/Context/Simple.pm line 71.

The Devel::Declare folks have basically said they can't fix it. We should document that limitation.

perl5i -e'use perl5i::2; is throwing a warning because it's effectively importing perl5i into the same namespace twice. That could probably be prevented.

perl -Mperl5i::2 -e works, I think, because Devel::Declare is loaded before Perl sees the -e line and has time to do its magic. The perl5i binary should be doing the equivalent of perl -Mperl5i::2 -e so it should work... and it does.

I see two actions out of this...

  • Document the perl -e 'use perl5i::2; ...' limitations and the perl5i -e and perl -Mperl5i::2 -e work arounds.
  • Allow loading perl5i::2 multiple times in the same namespace without warning.

I opened #251 for that second one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants