diff --git a/src/languages/perl.js b/src/languages/perl.js
index 7ffc6a02c1..4d53c2350a 100644
--- a/src/languages/perl.js
+++ b/src/languages/perl.js
@@ -26,6 +26,7 @@ export default function(hljs) {
'chown',
'chr',
'chroot',
+ 'class',
'close',
'closedir',
'connect',
@@ -55,6 +56,7 @@ export default function(hljs) {
'exit',
'exp',
'fcntl',
+ 'field',
'fileno',
'flock',
'for',
@@ -114,6 +116,7 @@ export default function(hljs) {
'lt',
'ma',
'map',
+ 'method',
'mkdir',
'msgctl',
'msgget',
@@ -258,19 +261,28 @@ export default function(hljs) {
end: /\}/
// contains defined later
};
- const VAR = { variants: [
- { begin: /\$\d/ },
- { begin: regex.concat(
- /[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
- // negative look-ahead tries to avoid matching patterns that are not
- // Perl at all like $ident$, @ident@, etc.
- `(?![A-Za-z])(?![@$%])`
- ) },
- {
- begin: /[$%@][^\s\w{]/,
- relevance: 0
- }
- ] };
+ const ATTRS = {
+ className: 'attribute',
+ begin: /\s+:\s*\w+/,
+ end: /(\\s*\\(.*?\\))?/,
+ };
+ const VAR = {
+ variants: [
+ { begin: /\$\d/ },
+ { begin: regex.concat(
+ /[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
+ // negative look-ahead tries to avoid matching patterns that are not
+ // Perl at all like $ident$, @ident@, etc.
+ `(?![A-Za-z])(?![@$%])`
+ )
+ },
+ {
+ begin: /[$%@][^\s\w{]/,
+ relevance: 0
+ }
+ ],
+ contains: [ ATTRS ],
+ };
const NUMBER = {
className: 'number',
variants: [
@@ -443,11 +455,19 @@ export default function(hljs) {
},
{
className: 'function',
- beginKeywords: 'sub',
+ beginKeywords: 'sub method',
end: '(\\s*\\(.*?\\))?[;{]',
excludeEnd: true,
relevance: 5,
- contains: [ hljs.TITLE_MODE ]
+ contains: [ hljs.TITLE_MODE, ATTRS ]
+ },
+ {
+ className: 'class',
+ beginKeywords: 'class',
+ end: '[;{]',
+ excludeEnd: true,
+ relevance: 5,
+ contains: [ hljs.TITLE_MODE, ATTRS, NUMBER ]
},
{
begin: '-\\w\\b',
diff --git a/test/markup/perl/class.expect.txt b/test/markup/perl/class.expect.txt
new file mode 100644
index 0000000000..94524ea8bf
--- /dev/null
+++ b/test/markup/perl/class.expect.txt
@@ -0,0 +1,12 @@
+use v5.38;
+
+use Object::Pad;
+
+class Example::Subclass :isa(Example::Base 2.345) {
+ field $_config :param :reader :writer;
+ field $_name : param = 'Test';
+
+ method test() {
+ $_name == 'Test' ? 'y' : 'n';
+ }
+}
diff --git a/test/markup/perl/class.txt b/test/markup/perl/class.txt
new file mode 100644
index 0000000000..e548863535
--- /dev/null
+++ b/test/markup/perl/class.txt
@@ -0,0 +1,12 @@
+use v5.38;
+
+use Object::Pad;
+
+class Example::Subclass :isa(Example::Base 2.345) {
+ field $_config :param :reader :writer;
+ field $_name : param = 'Test';
+
+ method test() {
+ $_name == 'Test' ? 'y' : 'n';
+ }
+}