Perl5 Package Manager

Perl5 Package Manager

Learn Languages 2018 in ODC (LL2018), 2018/08/26

E4967f90a08dadff9cc185b863cd99a7?s=128

Shoichi Kaji

August 26, 2018
Tweet

Transcript

  1. Perl5ͷ ύοέʔδϚωʔδϟ Shoichi Kaji

  2. Me • Shoichi Kaji • CPAN, github: skaji • the

    author of cpm
 (a Perl5 module installer)
  3. ͜ͷൃදͷ໨త • Perl5Λීஈ͋·Γ৮͍ͬͯͳ͍ਓΛର৅ʹ • ࠓޙɺPerl5Λ৮Ζ͏ͱͨ͠ͱ͖ͷͨΊʹ • moduleͷΠϯετʔϧ΍؅ཧͷ΍ΓํΛ
 ఏࣔ͢Δ

  4. Contents • moduleͷΠϯετʔϧ - cpanm • ґଘmoduleͷએݴ - cpanfile •

    ґଘmoduleͷversionอଘɺ࠶ݱ - carton • ·ͱΊ • ࠓޙͷಈ͖
  5. moduleͷΠϯετʔϧ › perl monitor.pl Can't locate Capture/Tiny.pm in @INC (you

    may need to install the Capture::Tiny module)… ͨͱ͑͹Perl5Ͱॻ͔Εͨ؂ࢹεΫϦϓτmonitor.pl͕ ͋Δͱ͢ΔɻͦΕΛ࣮ߦ͢Δͱ... Capture::Tiny͕ೖͬͯͳ͍
  6. moduleͷΠϯετʔϧ moduleͷΠϯετʔϧʹ͸cpanmΛ࢖͏ cpanmࣗ਎ͷΠϯετʔϧํ๏ # case1. globalʹೖΕΔ › curl https://cpanmin.us |

    perl - -n App::cpanminus # ΋͠perl͕system perlͷ৔߹͸ɺ΋ͪΖΜsudo͕ඞཁ › curl https://cpanmin.us | perl - -n --sudo App::cpanminus # case2. ؀ڥΛԚͨ͘͠ͳ͍৔߹͸ΧϨϯτσΟϨΫτϦʹऔͬͯ͘Ε͹Α͍ › curl -o cpanm https://cpanmin.us › perl ./cpanm --version
  7. moduleͷΠϯετʔϧ # Capture::TinyΛΠϯετʔϧ › cpanm -n Capture::Tiny Successfully installed Capture-Tiny-0.48

    › perl monitor.pl # WORkS!
  8. moduleͷΠϯετʔϧ # σϑΥϧτͰ͸୯ମςετΛ૸Β͔ͤͯΒΠϯετʔϧ͢Δ # -n ͰͦΕΛεΩοϓͰ͖Δ › cpanm -n Amon2

    # σϑΥϧτͰ͸ɺglobalͳσΟϨΫτϦʹmoduleΛΠϯετʔϧ͢Δ # ؀ڥΛԚͨ͘͠ͳ͍৔߹͸ɺ-L Λ࢖ͬͯΠϯετʔϧઌΛมߋ͢Δ › cpanm -L ./local Mojolicious # ࣮ߦ࣌͸ -I ͰͦͷσΟϨΫτϦΛsearch pathʹ௥Ճ͢Δ › perl -I ./local/lib/perl5 script.pl ͍͔ͭ͘ͷcpanmͷtips
  9. ґଘmoduleͷએݴ • ࣗ෼ͰPerl5ͷεΫϦϓτΛॻ͍ͨͱ͠Α͏ • ͍͔ͭ͘ґଘmodule͕͋Δ͚ΕͲɺ
 ͦΕΛͲ͏Ϣʔβʹ఻͑Ε͹͍͍ͷ͔ • cpanfileΛ࢖͓͏

  10. ґଘmoduleͷએݴ cpanfile - ґଘmoduleΛએݴ͢ΔϑΝΠϧ › cat cpanfile requires 'Plack', '1.0';

    # 1.0 or newer requires 'JSON', '>= 2.00, < 2.80'; # ୯ମςετ࣌ͷΈඞཁͳmodule on test => sub { requires 'Test::More', '== 1.302140'; recommends 'Test::TCP', '1.12'; };
  11. ґଘmoduleͷએݴ # cpanfile͕͋ΔσΟϨΫτϦͰcpanmΛ--installdepsͱͱ΋ʹ # ࣮ߦ͢Ε͹ґଘmoduleΛΠϯετʔϧͰ͖Δ › capnm -n --installdeps .

    # -L ͱ૊Έ߹ΘͤΕ͹ɺΧϨϯτσΟϨΫτϦʹ # ґଘmoduleΛΠϯετʔϧͰ͖Δ › cpanm -n -L ./local --installdeps . › perl -I ./local/lib/perl5 script.pl cpanfileʹґଘmoduleΛએݴ͢Ε͹
 cpanmͰ؆୯ʹΠϯετʔϧͰ͖Δ
  12. ґଘmoduleͷversionอଘɺ࠶ݱ • Perl5ͰຊࠊΛೖΕͯΞϓϦέʔγϣϯΛॻ͍͍ͯ͘ ͱɺґଘmodule͸͙͢ʹ100Λ௒͑Δ • ͢Δͱґଘmoduleͷversionʹහײʹͳͬͯ͘Δ • ։ൃ؀ڥͰςετΛpassͨ͠ͱ͖ͷґଘmoduleͷ versionΛ͢΂ͯอଘ͠ɺͦΕΛຊ൪Ͱ΋࠶ݱ͍ͨ͠ •

    cartonΛ࢖͓͏
  13. ґଘmoduleͷversionอଘɺ࠶ݱ # Cartonࣗ਎ͷΠϯετʔϧ › cpanm -n Carton # cpanfileͰએݴ͞ΕͨґଘmoduleΛ./localʹΠϯετʔϧ͢Δ ›

    carton install Complete! Modules were installed into …/local # Πϯετʔϧͨ͠moduleͷversion͸cpanfile.snapshotʹอଘ͞ΕΔ › ls cpanfile cpanfile.snapshot local # carton execͰ./localΛsearch pathʹೖΕͯperlΛىಈͰ͖Δ # (΋ͪΖΜɺcarton execΛ࢖Θͣࣗ෼Ͱ-IΛࢦఆͯ͠΋Α͍) › carton exec perl script.pl cartonΛ༻͍ͨ։ൃϑϩʔ(1)
  14. ґଘmoduleͷversionอଘɺ࠶ݱ # ͦͷޙɺผͷ؀ڥͰ΋--deploymentΛ͚ͭͯΠϯετʔϧ͢Δ͜ͱͰ # snapshotʹهड़͞ΕͨversionΛ࠶ݱͰ͖Δ › carton install --deployment Installing

    modules using …/cpanfile (deployment mode) Complete! Modules were installed into …/local cartonΛ༻͍ͨ։ൃϑϩʔ(2)
  15. ·ͱΊ • moduleͷΠϯετʔϧʹ͸cpanmΛ࢖͏ • ґଘmoduleͷએݴʹ͸cpanfileΛ࢖͏ • ґଘmoduleͷversionอଘɺ࠶ݱʹ͸
 cartonΛ࢖͏

  16. ࠓޙͷಈ͖ (πʔϧ) • moduleΠϯετʔϥͱͯ͠cpanmҎ֎ʹ
 CPAN.pm, CPANPLUS, cpmͳͲ͕͋Δ • cartonͷޙܧͱͯ͠carmel͕։ൃ͞Ε͍ͯΔ

  17. ࠓޙͷಈ͖ (࢓૊Έ) • Perl5Ͱ͸GNU Autotoolsͱಉ͡Α͏ʹϢʔβαΠυͰεΫϦϓτΛ࣮ߦͤ͞ɺΠ ϯετʔϧ࣌ͷڍಈΛಈతʹมԽͤ͞Δͷ͕ৗͰ͋ͬͨɻ
 Ұํɺେ఍ͷ৔߹͜Ε͸overkillͰ͋Γɺ੩తղੳͱ΋૬ੑ͕ѱ͍ɻ
 ͜Εʹର͠ɺࡢࠓɺ΋ͬͱγϯϓϧͳstatic installͱ͍͏Πϯετʔϧͷ࢓૊Έ͕ ఏҊ͞Ε͍ͯΔɻ

    • Perl5Ͱ͸ී௨ɺ͢΂ͯͷmoduleͨͪΛ͋ΔҰͭͷσΟϨΫτϦʹ·ͱΊͯΠϯ ετʔϧ͍ͯ͠Δɻ
 ͔͠͠ɺͦ͏ͯ͠͠·͏ͱɺͲͷmodule͕Ͳͷdistributionʹଐ͢Δͷ͔Θ͔Β ͳ͘ͳΓɺ؅ཧ͕͠ʹ͘͘ͳΔɻ
 ͜Εʹର͠ɺʮdistribuitonΛผʑʹ؅ཧ͠ɺ࣮ߦ࣌ʹͦΕΒΛద੾ʹsearch pathʹ഑ஔ͠Α͏ʯͱ͍͏ΞΠσΞ͕͋Γ carmel͸·͞ʹͦΕΛ࣮૷͍ͯ͠Δɻ