diff --git a/plugin/core/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.java b/plugin/core/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.java index 1b7dffab53..62008e1ffe 100644 --- a/plugin/core/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.java +++ b/plugin/core/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.java @@ -251,9 +251,23 @@ public class ExporterInfo implements Processor { private final @NotNull List EXPORT_OK = new ArrayList<>(); private final @NotNull Map> EXPORT_TAGS = Collections.emptyMap(); + // Deals with the following cases: + // use subs our @EXPORT_OK = qw( a b c ); + public PsiElement findAssignExpr(PsiElement element) { + PsiElement target = element.getFirstChild(); + while (target != null && !(target instanceof PsiPerlAssignExpr)) { + target = target.getNextSibling(); + } + return target; + } + public void extractExport(PsiElement element, String exportName, List target) { - PsiElement rightSide = element.getFirstChild().getLastChild(); - String variableName = element.getFirstChild().getFirstChild().getText(); + PsiElement assignExpr = findAssignExpr(element); + PsiElement leftSide = assignExpr.getFirstChild(); + PsiElement rightSide = assignExpr.getLastChild(); + String variableName = leftSide instanceof PerlVariableDeclarationExpr ? + leftSide.getLastChild().getText() : + leftSide.getText(); // @EXPORT or @{namespace}::EXPORT // @EXPORT_OK or @{namespace}::EXPORT_OK diff --git a/plugin/src/test/java/unit/perl/ExporterTest.java b/plugin/src/test/java/unit/perl/ExporterTest.java index 8336c17cb1..554738f2ac 100644 --- a/plugin/src/test/java/unit/perl/ExporterTest.java +++ b/plugin/src/test/java/unit/perl/ExporterTest.java @@ -34,6 +34,7 @@ protected String getBaseDataPath() { public void testExport() { doTest("export.pl", "Foo", new String[]{"this", "is", "the", "end"}, new String[]{}); doTest("boolean.pl", "boolean", new String[]{"true", "false", "boolean"}, new String[]{"isTrue", "isFalse", "isBoolean"}); + doTest("Opcode.pm", "Opcode", new String[]{}, new String[]{"opset", "opset_to_hex", "opdump"}); } @Test diff --git a/plugin/src/test/resources/unit/perl/exporter/Opcode.pm b/plugin/src/test/resources/unit/perl/exporter/Opcode.pm new file mode 100644 index 0000000000..251141af7a --- /dev/null +++ b/plugin/src/test/resources/unit/perl/exporter/Opcode.pm @@ -0,0 +1,14 @@ +package Opcode 1.64; + +use strict; + +use Carp; +use Exporter 'import'; +use XSLoader; + +sub opset (;@); +sub opset_to_hex ($); +sub opdump (;$); +use subs our @EXPORT_OK = qw( + opset opset_to_hex opdump +); \ No newline at end of file