Compiler::Lexer(3pm)
β¨ NAME β¨
so basically, bestie, this is Compiler::Lexer(3pm) from the User Contributed Perl Documentation, and it's a Lexical Analyzer for Perl5. like, it takes your Perl source and hands you back a whole lil' pile of tokens. iconic behavior honestly π¦
πΈ SYNOPSIS πΈ
here's the whole vibe, copy-paste ready, no cap:
use Compiler::Lexer;
use Data::Dumper;
my $filename = $ARGV[0];
open my $fh, '<', $filename or die "Cannot open $filename: $!";
my $script = do { local $/; <$fh> };
my $lexer = Compiler::Lexer->new($filename);
my $tokens = $lexer->tokenize($script);
print Dumper $tokens;
my $modules = $lexer->get_used_modules($script);
print Dumper $modules;
π METHODS π
my $lexer = Compiler::Lexer->new($options);
make yourself a shiny new instance, periodt. and yes you can build the object from $options in a hash reference β very main character of it π
here's the options list:
filenameβ the file name, obviously, she's the starverboseβ includes token of Pod, Comment and WhiteSpace. so when you turn this on you get the chatty version, pods and comments and whitespace all up in the token list π
$lexer->tokenize($script);
get token objects includes parameter of name or type or line and so on. this method requires perl source code in string. that's it, that's the whole thing β hand her a string, get tokens back π₯
$lexer->set_library_path(['path1', 'path2' ...])
set libraries path for reading recursively. Default paths are @INC. so if your modules are living somewhere off the beaten path, this is your moment π
$lexer->recursive_tokenize($script)
get hash reference like { 'module_nameA' => [], 'module_nameB' => [] ... }. This method requires per source code in string π§
$lexer->get_used_modules($script);
get names of used module. This method requires perl source code in string. so like, who's she importing? this tells you. obsessed β¨
π AUTHOR π
Masaaki Goshima (goccy) <goccy(at)cpan.org>
π CONTRIBUTORS π
- tokuhirom: Tokuhiro Matsuno
π LICENSE AND COPYRIGHT π
Copyright (c) 2013, Masaaki Goshima (goccy). All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
aaand that's the whole page bestie, you ate it π this lil' legend ships as perl v5.42.3, dated 2026-08-19, and it's the Compiler::Lexer(3pm) page β go tokenize something gorgeous π«Ά
π¦ where this page comes from
- ubuntu stonking: libcompiler-lexer-perl 0.23-3build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms