perlmodule-build

How can I ensure that files without extensions are installed using Module::Build?


I am converting an inherited software collection to a Module::Build based distribution.

The lib directories contain, in addition to the .pm files, certain external files needed by the modules. It is easy to ensure that the ones that have extensions are copied along with the .pm files by using Module::Build's add_build_element method.

But I am confused about how to deal with files that have no extensions. How can I make sure those files are also copied alongside the .pm files during installation? Is there a way to tell Module::Build to copy everything under lib?


Solution

  • Build.PL

    use lib 'inc';
    use Local::Module::Build::Extensionless;
    
    my $build = Local::Module::Build::Extensionless->new(
        module_name => 'Foo::Bar',
        license     => 'restricted',
    );
    $build->add_build_element('lib');
    $build->create_build_script;
    

    inc/Local/Module/Build/Extensionless.pm

    package Local::Module::Build::Extensionless;
    use parent 'Module::Build';
    use File::Next qw();
    
    sub process_lib_files {
        my ($self) = @_;
        my $files;
    
        {
            my $iter = File::Next::files('lib');
            while (defined(my $file = $iter->())) {
                $files->{$file} = $file;
            }
        }
    
        # following piece from Module::Build::Base::process_files_by_extension
        while (my ($file, $dest) = each %$files) {
            $self->copy_if_modified(from => $file, to => File::Spec->catfile($self->blib, $dest));
        }
    };
    1;
    

    But why so complicated? You really want share_dir.