I ran into a situation where I wanted to use cpanm to install modules for later packaging.
Even though ExtUtils::MakeMaker and Module::Build were honoring the DESTDIR/destdir flags when passed in using PERL_MM_OPT/PERL_MB_OPT, cpanm's write check on the install directories was failing, causing cpanm to fall back to ~/perl5 as the install location.
This pull request tries to use DESTDIR/destdir if they are set in PERL_MM_OPT/PERL_MB_OPT when doing the write check.
Check for writable location if DESTDIR/destdir set
Parse PERL_MB_OPT better if multiple values
Break logic into dest_dir and use in save_meta
Use DESTDIR when checking dependencies and testing
Note that this patch won't catch destdir if it's defined in MODULEBUILDRC.
Ok, these changes ended up being more unwieldy than I expected. Not sure this is the best way to address supporting DESTDIR/destdir.