Lang::Go::Mod - parse and model go.mod files
Lang::Go::Mod
# $ cat go.mod # module github.com/example/my-project # go 1.16 # // comments # exclude ( # example.com/whatmodule v1.4.0 # ) # replace ( # github.com/example/my-project/pkg/app => ./pkg/app # ) # require ( # golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect # ) use Lang::Go::Mod qw(read_go_mod parse_go_mod); my $go_mod_path = '/path/to/go.mod'; # read and parse the go.mod file # all errors croak, so wrap this in your favorite variant of try/catch # to gracefully manage errors my $m = read_go_mod($go_mod_path); # use parse_go_mod to parse the go.mod content if it is already in a scalar print $m->{module}; # github.com/example/my-project print $m->{go}; # 1.16 print $m->{exclude}->{'example.com/whatmodule'}; # [v1.4.0] print $m->{replace}->{'github.com/example/my-project/pkg/app'}; # ./pkg/app print $m->{'require'}->{'golang.org/x/sys'}; # v0.0.0-20210510120138-977fb7262007
This module creates a hash representation of a go.mod file. Both single line and multiline exclude, replace, and require sections are supported. For a full reference of the go.mod format, see
go.mod
exclude
replace
require
https://golang.org/doc/modules/gomod-ref
read_go_mod
Given a full filepath for a go.mod file, read it, parse it and return the hash representation of the contents. All errors croak.
croak
parse_go_mod
Given a scalar of the contents of a go.mod file, parse it and return the hash representation of the contents. All errors croak.
Lang::Go::Mod is licensed under the same terms as Perl itself.
https://opensource.org/licenses/artistic-license-2.0
Ben Bullock (https://github.com/benkasminbullock)
To install Lang::Go::Mod, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lang::Go::Mod
CPAN shell
perl -MCPAN -e shell install Lang::Go::Mod
For more information on module installation, please visit the detailed CPAN module installation guide.