CPANfile::Parse::PPI - Parse cpanfiles with PPI
version 0.05
use v5.24; use CPANfile::Parse::PPI; my $path = '/path/to/cpanfile'; my $cpanfile = CPANfile::Parse::PPI->new( $path ); # or # my $cpanfile = CPANfile::Parse::PPI->new( \$content ); for my $module ( $cpanfile->modules->@* ) { my $stage = ""; $stage = "on $module->{stage}" if $module->{stage}; say sprintf "%s is %s", $module->{name}, $module->{type}; }
my $path = '/path/to/cpanfile'; my $cpanfile = CPANfile::Parse::PPI->new( $path ); # or my $content = <<'CPANFILE'; requires "CPANfile::Parse::PPI" => 3.6;'; on build => sub { recommends "Dist::Zilla" => 4.0; requires "Test2" => 2.311; } CPANFILE my $cpanfile = CPANfile::Parse::PPI->new( \$content );
Returns information about mirrors and OS name - if given in the cpanfile
Returns a list of modules mentioned in the cpanfile ("perl" is skipped). Each element is a hashref with these keys:
name
version
type
stage
use CPANfile::Parse::PPI; use Data::Printer; my $required = 'requires "CPANfile::Parse::PPI" => 3.6;'; my $cpanfile = CPANfile::Parse::PPI->new( \$required ); my $modules = $cpanfile->modules; p $modules; __DATA__ [ [0] { name "CPANfile::Parse::PPI", stage "", type "requires", version 3.6 } ]
As this is a static parser, this module cannot handle dynamic code like
for my $module (qw/ IO::All Zydeco::Lite::App /) { requires $module, '0'; }
This module warns when the required "module" doesn't look like a package name.
You can make it die when you pass -strict to the module when you load it:
-strict
use CPANfile::Parse::PPI -strict; use Data::Printer; my $required = do { local $/; <DATA> }; my $cpanfile = CPANfile::Parse::PPI->new( \$required ); my $modules = $cpanfile->modules; __DATA__ for my $module (qw/ IO::All Zydeco::Lite::App /) { requires $module, '0'; }
Renee Baecker <reneeb@cpan.org>
This software is Copyright (c) 2020 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install CPANfile::Parse::PPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CPANfile::Parse::PPI
CPAN shell
perl -MCPAN -e shell install CPANfile::Parse::PPI
For more information on module installation, please visit the detailed CPAN module installation guide.