Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CPAN Module Hacks

akiym
January 26, 2019

CPAN Module Hacks

YAPC::Tokyo 2019

akiym

January 26, 2019
Tweet

More Decks by akiym

Other Decks in Technology

Transcript

  1. *.pm distribution module package Foo; our $VERSION = '0.01'; package

    Bar; ... 例: libwww-perl 例: LWP/UserAgent.pm LWP::UserAgent
  2. PAUSE (Perl Authors Upload SErver) PAUSE ID CPAN Index (CPAN上にあるすべてのパッケージの⼀覧)

    http://cpan.org/modules/02packages.details.txt.gz LWP::Simple 6.36 E/ET/ETHER/libwww-perl-6.36.tar.gz LWP::UserAgent 6.36 E/ET/ETHER/libwww-perl-6.36.tar.gz ... indexing アップロードされたdistributionから 使われているpackageを解析する libwww-perl-6.36.tar.gz release PAUSEにtarballを アップロード tarballの⽣成やアップロードは オーサリングツールを使う
  3. % cpanm LWP::UserAgent --> Working on LWP::UserAgent Fetching http://www.cpan.org/authors/id/E/ET/ETHER/ libwww-perl-6.36.tar.gz

    ... OK Configuring libwww-perl-6.36 ... OK Building libwww-perl-6.36 ... OK Successfully installed libwww-perl-6.36 1 distribution installed
  4. CPANクライアント cpanmetadb BackPAN CPAN mirror 02packages.details.txt www.cpan.org ① packageから distributionの解決を⾏う

    ② tarballを取ってくる E/ET/ETHER/libwww-perl-6.36.tar.gz http://www.cpan.org/authors/id/E/ET/ETHER/libwww-perl-6.36.tar.gz cpanm LWP::UserAgent or cpanm LWP::[email protected]
  5. CPANクライアント cpanmetadb BackPAN CPAN mirror 02packages.details.txt www.cpan.org ① packageから distributionの解決を⾏う

    ② tarballを取ってくる E/ET/ETHER/libwww-perl-6.36.tar.gz http://www.cpan.org/authors/id/E/ET/ETHER/libwww-perl-6.36.tar.gz ③ 依存モジュールの解決 Makefile.PL / Build.PLの実⾏のちインストールされる cpanm LWP::UserAgent or cpanm LWP::[email protected]
  6. % minil new Foo::Bar % cd Foo-Bar % tree ├──

    Build.PL ├── Changes ├── LICENSE ├── META.json ├── README.md ├── cpanfile ├── lib │ └── Foo │ └── Bar.pm ├── minil.toml └── t └── 00_compile.t 3 directories, 9 files
  7. % carton install Installing modules using /path/to/cpanfile Successfully installed Module-Pluggable-5.2

    Successfully installed Importer-0.025 Successfully installed Test-Simple-1.302160 (upgraded from 1.302073) Successfully installed Scope-Guard-0.21 Successfully installed Term-Table-0.013 Successfully installed Sub-Info-0.002 Successfully installed Test2-Suite-0.000118 7 distributions installed Complete! Modules were installed into /path/to/local % tree . ├── cpanfile ├── cpanfile.snapshot └── local ├── cache │ └── ... └── lib └── perl5 ├── ... cpanfileより 依存モジュールをlocal/以下に インストール
  8. # carton snapshot format: version 1.0 DISTRIBUTIONS Importer-0.025 pathname: E/EX/EXODIST/Importer-0.025.tar.gz

    provides: Importer 0.025 requirements: ExtUtils::MakeMaker 0 perl 5.008001 ... cpanfile.snapshotを吐く
  9. % cpan-audit deps Discovered 1 dependencies Mojolicious (requires 7.83) has

    1 advisories * CPANSA-Mojolicious-2018-04 This release reverts the addition of stream classes (added in 7.83), which have unfortunately resulted in many Mojolicious applications becoming unstable. While there are no known exploits yet, we've chosen to err on the side of cautiousness and will classify this as a security issue. Affected range: >7.83, <7.92 References: https://github.com/mojolicious/mojo/commit/61f6cbf22c7bf8eb4787bd1014d91ee2416c73e7 Total advisories found: 1
  10. requires 'Path::Class', 0.26, dist => "KWILLIAMS/Path-Class-0.26.tar.gz"; requires 'Hash::MultiValue', dist =>

    "MIYAGAWA/Hash-MultiValue-0.15.tar.gz"; requires 'Cookie::Baker', dist => "KAZEBURO/Cookie-Baker-0.08.tar.gz", mirror => "http://cpan.cpantesters.org/"; requires 'Try::Tiny', 0.28, url => "http://backpan.perl.org/authors/id/E/ET/ETHER/Try-Tiny-0.28.tar.gz"; cpanfileに以下のように書くだけ
  11. requires 'Private::Module', dist => "AKIYM/Private-Module-0.01.tar.gz", mirror => "https://xxx.s3-ap-northeast-1.amazonaws.com/"; • /authors/id/A/AK/AKIYM/Private-Module-0.01.tar.gz


    として配置する必要がある • bucketがパブリックアクセスにならないようにする
 (使うときにはIPアドレス制限など) • Menlo >= 1.0913
  12. # carton snapshot format: version 1.0 DISTRIBUTIONS Importer-0.025 pathname: E/EX/EXODIST/Importer-0.025.tar.gz

    provides: Importer 0.025 requirements: ExtUtils::MakeMaker 0 perl 5.008001 ... mirrorの指定はできない
  13. % cpm install -v Loading distributions from cpanfile.snapshot... 73951 DONE

    resolve (0.003sec) Private::Module -> Private-Module-0.01 (from CPANfile) 73950 DONE resolve (0.005sec) Test::More -> Test-Simple-1.302140 (from Snapshot) 73950 DONE fetch (0.032sec) Test-Simple-1.302140 (using prebuilt) 73951 DONE fetch (0.323sec) Private-Module-0.01 73951 DONE configure (0.030sec) Private-Module-0.01 73951 DONE install (0.289sec) Private-Module-0.01 73950 DONE install (0.766sec) Test-Simple-1.302140 (using prebuilt) 2 distributions installed. ここはcpanfileから解決 cpanfile.snapshot