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

Perl5 Package Manager

Perl5 Package Manager

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

Shoichi Kaji

August 26, 2018
Tweet

More Decks by Shoichi Kaji

Other Decks in Technology

Transcript

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

    author of cpm
 (a Perl5 module installer)
  2. Contents • moduleͷΠϯετʔϧ - cpanm • ґଘmoduleͷએݴ - cpanfile •

    ґଘmoduleͷversionอଘɺ࠶ݱ - carton • ·ͱΊ • ࠓޙͷಈ͖
  3. 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͕ೖͬͯͳ͍
  4. 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
  5. moduleͷΠϯετʔϧ # σϑΥϧτͰ͸୯ମςετΛ૸Β͔ͤͯΒΠϯετʔϧ͢Δ # -n ͰͦΕΛεΩοϓͰ͖Δ › cpanm -n Amon2

    # σϑΥϧτͰ͸ɺglobalͳσΟϨΫτϦʹmoduleΛΠϯετʔϧ͢Δ # ؀ڥΛԚͨ͘͠ͳ͍৔߹͸ɺ-L Λ࢖ͬͯΠϯετʔϧઌΛมߋ͢Δ › cpanm -L ./local Mojolicious # ࣮ߦ࣌͸ -I ͰͦͷσΟϨΫτϦΛsearch pathʹ௥Ճ͢Δ › perl -I ./local/lib/perl5 script.pl ͍͔ͭ͘ͷcpanmͷtips
  6. ґଘ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'; };
  7. ґଘ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Ͱ؆୯ʹΠϯετʔϧͰ͖Δ
  8. ґଘ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)
  9. ґଘmoduleͷversionอଘɺ࠶ݱ # ͦͷޙɺผͷ؀ڥͰ΋--deploymentΛ͚ͭͯΠϯετʔϧ͢Δ͜ͱͰ # snapshotʹهड़͞ΕͨversionΛ࠶ݱͰ͖Δ › carton install --deployment Installing

    modules using …/cpanfile (deployment mode) Complete! Modules were installed into …/local cartonΛ༻͍ͨ։ൃϑϩʔ(2)
  10. ࠓޙͷಈ͖ (࢓૊Έ) • Perl5Ͱ͸GNU Autotoolsͱಉ͡Α͏ʹϢʔβαΠυͰεΫϦϓτΛ࣮ߦͤ͞ɺΠ ϯετʔϧ࣌ͷڍಈΛಈతʹมԽͤ͞Δͷ͕ৗͰ͋ͬͨɻ
 Ұํɺେ఍ͷ৔߹͜Ε͸overkillͰ͋Γɺ੩తղੳͱ΋૬ੑ͕ѱ͍ɻ
 ͜Εʹର͠ɺࡢࠓɺ΋ͬͱγϯϓϧͳstatic installͱ͍͏Πϯετʔϧͷ࢓૊Έ͕ ఏҊ͞Ε͍ͯΔɻ

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