2

I would like to check syntax of my perl module (as well as for imports), but I don't want to check for dynamic loaded c libraries.

If I do:

perl -c path_to_module

I get:

Can't locate loadable object for module B::Hooks::OP::Check in @INC

because B::Hooks::OP::Check are loading some dynamic c libraries and I don't want to check that...

Slaven Tomac
  • 1,552
  • 2
  • 26
  • 38
  • If a library isn't available, how do you know if it's a C or pure Perl library? Do you have a well-defined list of libraries you want to ignore, or should all missing libraries be trapped? (In the latter case, how do you plan to distinguish a load failure from a real error?) – tripleee Nov 19 '13 at 15:08
  • This error: Can't locate loadable object for module B::Hooks::OP::Check is different than: Can't locate B/Hooks/OP/Checkaa.pm (I've changed name of import here) I just don't want to load dynamic c libraries to so I can check perl syntax anywhere where modules are... – Slaven Tomac Nov 19 '13 at 15:10

2 Answers2

6

You can't.

Modules can affect the scripts that use them in many ways, including how they are parsed.

For example, if a module exports

sub f() { }

Then

my $f = f+4;

means

my $f = f() + 4;

But if a it were to export

sub f { }

the same code means

my $f = f(+4);

As such, modules must be loaded to parse the script that loads it. To load a module is simply to execute it, be it written in Perl or C.


That said, some folks put together PPI to address the needs of people like you. It's not perfect —it can't be perfect for the reasons previously stated— but it will give useful results nonetheless.


By the way, the proper way to syntax check a module is

perl -e'use Module;'

Using -c can give errors where non exists and vice-versa.

ikegami
  • 367,544
  • 15
  • 269
  • 518
2

The syntax checker loads the included libraries because they might be applying changes to the syntax. If you're certain that this is not happening, you could prevent the inclusion by manipulating the loading path and providing a fake b::Hooks::OP::Check.

alexis
  • 48,685
  • 16
  • 101
  • 161