View Issue Details

IDProjectCategoryView StatusLast Update
0000464fileGeneralpublic2023-07-17 16:01
Reporterjpalus Assigned Tochristos  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.44 
Fixed in Version5.45 
Summary0000464: Perl module with package version not detected as Perl source
DescriptionSample Perl file:

$ cat test.pm
package foo 1.0;

is not detected as Perl source:

$ file test.pm
test.pm: ASCII text

That's because current pattern does not cover optional version following package name. Attached two patches:
1. Change perl detection regexes to use [:space:] class instead of fixed space
2. Add support for version following package name as per https://perldoc.perl.org/functions/package
TagsNo tags attached.

Activities

jpalus

2023-07-05 11:02

reporter  

0001-perl-use-space-class-instead-of-fixed-spaces.patch (1,079 bytes)   
From 32f07f408ffb920442072b06fd2e2fe15c7a48f2 Mon Sep 17 00:00:00 2001
From: Jan Palus <jpalus@fastmail.com>
Date: Wed, 5 Jul 2023 12:09:50 +0200
Subject: [PATCH 1/2] perl: use [:space:] class instead of fixed spaces

---
 magic/Magdir/perl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/magic/Magdir/perl b/magic/Magdir/perl
index c391d4a7..db1d633e 100644
--- a/magic/Magdir/perl
+++ b/magic/Magdir/perl
@@ -34,12 +34,12 @@
 # by Dmitry V. Levin and Alexey Tourbin
 # check the first line
 0	search/8192	package
->0	regex		\^package[\ \t]+[0-9A-Za-z_:]+\ *;	Perl5 module source text
+>0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*;	Perl5 module source text
 !:strength + 40
 # not 'p', check other lines
 0	search/8192	!p
->0	regex		\^package[\ \t]+[0-9A-Za-z_:]+\ *;
->>0	regex		\^1\ *;|\^(use|sub|my)\ .*[(;{=]	Perl5 module source text
+>0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*;
+>>0	regex		\^1[[:space:]]*;|\^(use|sub|my)[[:space:]].*[(;{=]	Perl5 module source text
 !:strength + 75
 
 # Perl POD documents
-- 
2.41.0

0002-perl-detect-files-with-version-after-package-name.patch (1,418 bytes)   
From 355103d5873351b491db96e0b432d3c00de67b09 Mon Sep 17 00:00:00 2001
From: Jan Palus <jpalus@fastmail.com>
Date: Wed, 5 Jul 2023 12:12:06 +0200
Subject: [PATCH 2/2] perl: detect files with version after package name

as per https://perldoc.perl.org/functions/package perl allows to give
version after package name so in addition to:

package <package-name>;

add support for detecting:

package <package-name> <version>;

where <version> is version string consisting of numbers and dotts,
optionally prefixed with 'v'. Examples:

v1.2.3
1.0
---
 magic/Magdir/perl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/magic/Magdir/perl b/magic/Magdir/perl
index db1d633e..d4e8080e 100644
--- a/magic/Magdir/perl
+++ b/magic/Magdir/perl
@@ -34,11 +34,11 @@
 # by Dmitry V. Levin and Alexey Tourbin
 # check the first line
 0	search/8192	package
->0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*;	Perl5 module source text
+>0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*([[:space:]]v?[0-9][0-9.]*)?[[:space:]]*;	Perl5 module source text
 !:strength + 40
 # not 'p', check other lines
 0	search/8192	!p
->0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*;
+>0	regex		\^package[[:space:]]+[0-9A-Za-z_:]+[[:space:]]*([[:space:]]v?[0-9][0-9.]*)?[[:space:]]*;
 >>0	regex		\^1[[:space:]]*;|\^(use|sub|my)[[:space:]].*[(;{=]	Perl5 module source text
 !:strength + 75
 
-- 
2.41.0

christos

2023-07-17 16:01

manager   ~0003959

Applied thanks!

Issue History

Date Modified Username Field Change
2023-07-05 11:02 jpalus New Issue
2023-07-05 11:02 jpalus File Added: 0001-perl-use-space-class-instead-of-fixed-spaces.patch
2023-07-05 11:02 jpalus File Added: 0002-perl-detect-files-with-version-after-package-name.patch
2023-07-17 16:01 christos Assigned To => christos
2023-07-17 16:01 christos Status new => assigned
2023-07-17 16:01 christos Status assigned => resolved
2023-07-17 16:01 christos Resolution open => fixed
2023-07-17 16:01 christos Fixed in Version => 5.45
2023-07-17 16:01 christos Note Added: 0003959