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

課題をテストで解決する

shibayu36
April 20, 2014

 課題をテストで解決する

shibayu36

April 20, 2014
Tweet

More Decks by shibayu36

Other Decks in Programming

Transcript

  1. ՝୊ΛςετͰղܾ͢Δ
    DevLOVEؔ੢ 2014/04/19
    shiba_yu36

    View full-size slide

  2. !TIJCB@ZV
    • ͸ͯͳΞϓϦέʔγϣϯΤϯδχΞ
    • ͸ͯͳϒϩάνʔϜ
    • PerlɺςετɺσϓϩΠɺ։ൃ؀ڥ

    View full-size slide

  3. ϒϩά
    http://shibayu36.hatenablog.com/

    View full-size slide

  4. ࠓ೔ͷ࿩
    ͸ͯͳϒϩάͷςετ
    ՝୊Λղܾ͢Δςετࣄྫ
    ՝୊ͱςετ

    View full-size slide

  5. ͸ͯͳϒϩάͷςετ

    View full-size slide

  6. UFTUT
    UFTUTNP
    CVJMETEBZ NJOCVJME
    FOHJOFFST

    View full-size slide

  7. Perlͷ୯ମςετ
    ;Δ·͍ςετ
    Model DB
    Controller View
    JavaScript
    lint
    ͦͷଞ
    crontab
    nginx
    ઃఆ߲໨
    syntax

    View full-size slide

  8. ςετͷํ਑
    • શͯͷϝιουΛςετ
    • PerlҎ֎ͷ෦෼΋
    • ՝୊ΛςετͰΧόʔ

    View full-size slide

  9. ςετͷํ਑
    • શͯͷϝιουΛςετ
    • PerlҎ֎ͷ෦෼΋
    • ՝୊ΛςετͰΧόʔ

    View full-size slide

  10. ՝୊ΛςετͰΧόʔʁ

    View full-size slide

  11. ՝୊ʁ
    ॻࣜϛε
    ຋༁๨Ε
    υΩϡϝϯτ
    σβΠφͱͷڠۀ
    ઃఆϛε

    View full-size slide

  12. ՝୊ʁ
    ॻࣜϛε
    ຋༁๨Ε
    υΩϡϝϯτ
    σβΠφͱͷڠۀ
    ઃఆϛε
    ਓ͕ؾΛ͚ͭΔ

    View full-size slide

  13. ਓ͕ؾΛ͚ͭΔ
    ՝୊ʁ
    ॻࣜϛε
    ຋༁๨Ε
    υΩϡϝϯτ
    σβΠφͱͷڠۀ
    ઃఆϛε
    ςετͰΧόʔ

    View full-size slide

  14. ՝୊Λղܾ͢Δςετ

    View full-size slide

  15. ݴޠʹΑΒͳ͍
    ՝୊ͱςετ
    ݴޠʹΑΔ
    ୯ମςετ

    View full-size slide

  16. ՝୊1
    crontabΛσϓϩΠͨ͠Β
    ಈ͔ͳ͔ͬͨ

    View full-size slide

  17. • crontabͷॻࣜϛε
    • ࢦఆͨ͠ϑΝΠϧύεΛؒҧ͑Δ
    • ϩδοΫϛε -> ςετ͋ΔͷͰ΄ͱΜͲͳ͍
    ݪҼ

    View full-size slide

  18. ݪҼ
    • crontabͷॻࣜϛε
    • ࢦఆͨ͠ϑΝΠϧύεΛؒҧ͑Δ
    • ϩδοΫϛε -> ςετ͋ΔͷͰ΄ͱΜͲͳ͍
    ਓ͕ؾΛ͚ͭΔ
    ςετͰΧόʔ

    View full-size slide

  19. ςετ͍ͨ͜͠ͱ
    [email protected]!
    10 5 * * * apache perl /path/to/dir/script/echo.pl!
    30 09 * * * apache perl /path/to/dir/script/sleep.pl

    View full-size slide

  20. ςετ͍ͨ͜͠ͱ
    [email protected]!
    10 5 * * * apache perl /path/to/dir/script/echo.pl!
    30 09 * * * apache perl /path/to/dir/script/sleep.pl
    ϑΝΠϧऴ୺ʹվߦ͋Δ
    ࢦఆϑΝΠϧଘࡏ͢Δ
    ೔෇ࢦఆਖ਼͍͠

    View full-size slide

  21. ϑΝΠϧऴ୺ʹվߦ͋Δ?
    my $crontab = file('config/crontab')->slurp;!
    like $crontab, qr/\n$/, 'ϑΝΠϧ຤ඌʹվߦඞཁ';
    ϑΝΠϧ಺༰Λ
    ਖ਼نදݱͰνΣοΫ

    View full-size slide

  22. ࢦఆϑΝΠϧଘࡏ͢Δ?
    my @files = $crontab =~ m{/path/to/dir/(.*\.pl)}g;!
    !
    for my $file (@files) {!
    ok -e $file, "$file ͕ଘࡏ";!
    }

    View full-size slide

  23. ࢦఆϑΝΠϧଘࡏ͢Δ?
    my @files = $crontab =~ m{/path/to/dir/(.*\.pl)}g;!
    !
    for my $file (@files) {!
    ok -e $file, "$file ͕ଘࡏ";!
    }
    QSPKFDU಺ͬΆ͍ϑΝΠϧ୳͢
    ͦΕͧΕϑΝΠϧ͋Δ͔

    View full-size slide

  24. ߋʹςετ͢Δ
    • crontabͷParser࣮૷Λ࢖͏
    • PerlͩͱParse::Crontab
    • ೔෇ͷࢦఆϛεͱ͔νΣοΫͯ͘͠ΕΔ

    View full-size slide

  25. গ͠ͷςετͰਓ͕
    ؾΛ͚ͭΔඞཁແ͘ͳͬͨ

    View full-size slide

  26. ՝୊2
    ઃఆϛεΛͯ͠
    σϓϩΠͯ͠͠·ͬͨ

    View full-size slide

  27. ΞϓϦέʔγϣϯͷઃఆ
    • ؀ڥ͝ͱͷઃఆͱ͔
    • DBʹ֨ೲ͢Δ·Ͱ΋ͳ͍σʔλ
    • etc

    View full-size slide

  28. [!
    {!
    "blog_url" : "http://shibayu36.hatenablog.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "shiba_yu36"!
    ]!
    },!
    {!
    "blog_url" : "http://shibayu36-private.hatenablog.com/",!
    "permission" : "private",!
    "can_be_edited_by" : [!
    "shiba_yu36",!
    "shiba_yu37"!
    ]!
    },!
    {!
    "blog_url" : "http://blog.example.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "example-user"!
    ]!
    }!
    ]

    View full-size slide

  29. [!
    {!
    "blog_url" : "http://shibayu36.hatenablog.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "shiba_yu36"!
    ]!
    },!
    {!
    "blog_url" : "http://shibayu36-private.hatenablog.com/",!
    "permission" : "private",!
    "can_be_edited_by" : [!
    "shiba_yu36",!
    "shiba_yu37"!
    ]!
    },!
    {!
    "blog_url" : "http://blog.example.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "example-user"!
    ]!
    }!
    ]
    CMPH@VSM͸63-Ͱ͋Δ

    View full-size slide

  30. [!
    {!
    "blog_url" : "http://shibayu36.hatenablog.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "shiba_yu36"!
    ]!
    },!
    {!
    "blog_url" : "http://shibayu36-private.hatenablog.com/",!
    "permission" : "private",!
    "can_be_edited_by" : [!
    "shiba_yu36",!
    "shiba_yu37"!
    ]!
    },!
    {!
    "blog_url" : "http://blog.example.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "example-user"!
    ]!
    }!
    ]
    QFSNJTTJPO͸
    QVCMJD͔QSJWBUF

    View full-size slide

  31. [!
    {!
    "blog_url" : "http://shibayu36.hatenablog.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "shiba_yu36"!
    ]!
    },!
    {!
    "blog_url" : "http://shibayu36-private.hatenablog.com/",!
    "permission" : "private",!
    "can_be_edited_by" : [!
    "shiba_yu36",!
    "shiba_yu37"!
    ]!
    },!
    {!
    "blog_url" : "http://blog.example.com/",!
    "permission" : "public",!
    "can_be_edited_by" : [!
    "example-user"!
    ]!
    }!
    ]
    CMPH@VSM͸
    શମͰϢχʔΫ

    View full-size slide

  32. Ͳ͏΍ͬͯ࢓༷Λ఻͑Δ?
    υΩϡϝϯτ
    ؾ͔ͮΕͳ͍
    ϛεΛ͢Δ

    View full-size slide

  33. ͜Ε΋ςετʹͯ͠͠·͏

    View full-size slide

  34. my $blogs_config = decode_json(file('blogs.json')->slurp);!
    !
    for my $config (@$blogs_config) {!
    !
    my $blog_url = URI->new($config->{blog_url});!
    is $blog_url->scheme, 'http', "blog_url͸httpͷURLͰ͋Δ";!
    !
    cmp_deeply $config->{permission}, any('public', 'private'),!
    'permission͸public͔privateͰ͋Δ';!
    }

    View full-size slide

  35. my $blogs_config = decode_json(file('blogs.json')->slurp);!
    !
    for my $config (@$blogs_config) {!
    !
    my $blog_url = URI->new($config->{blog_url});!
    is $blog_url->scheme, 'http', "blog_url͸httpͷURLͰ͋Δ";!
    !
    cmp_deeply $config->{permission}, any('public', 'private'),!
    'permission͸public͔privateͰ͋Δ';!
    }
    CMPH@VSM͸63-Ͱ͋Δ
    QFSNJTTJPO͸
    QVCMJD͔QSJWBUF

    View full-size slide

  36. CMPH@VSM͸
    શମͰϢχʔΫ
    my $blogs_config_uniq = [!
    uniq_by { $_->{blog_url} } @$blogs_config,!
    ];!
    !
    is scalar @$blogs_config_uniq,!
    scalar @$blogs_config,!
    "blog_url͕શମͰϢχʔΫͰ͋Δ";

    View full-size slide

  37. υΩϡϝϯτ͔Βςετʹ
    • ؾ෇͔Εͳͯ͘΋ɺςετ͕མͪͯ஌Βͤ
    ͯ͘ΕΔ
    • ϛε͕͋ͬͯ΋ςετͰݕ஌

    View full-size slide

  38. IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ

    ઃఆͷ࢓༷ΛυΩϡϝϯτʹ
    ॻ͘ͷͰ͸ͳ͘ɺςετʹͯ͠͠·͏

    View full-size slide

  39. ൃల
    • ઃఆͷΫϥεΛ࡞Δ
    • http://hitode909.hatenablog.com/entry/
    2014/04/10/114403

    View full-size slide

  40. ՝୊3
    ຋༁Λ๨Εͯ
    σϓϩΠͯ͠͠·ͬͨ

    View full-size slide

  41. ଟݴޠରԠͷ࢓૊Έ
    CMPHNBOBHF
    MPD bCMPHNBOBHF`

    ϒϩά؅ཧ .BOBHF#MPH

    View full-size slide

  42. !
    !
    [% loc('blog.manage') %]!
    !
    !
    [% loc('blog.manage.description') %]!
    !

    !
    !
    [% loc('blog.manage') %]!
    !
    !
    ϒϩά؅ཧ͕Ͱ͖·͢!
    !

    View full-size slide

  43. Ͳ͏΍ͬͯݕ஌͢Δ͔
    • Viewʹ೔ຊޠ͕ೖͬͯͳ͍͜ͱͷςετ
    • ೔ຊਓͳͷͰɺେ఍͜ΕͰղܾͰ͖Δ

    View full-size slide

  44. my @files = glob('templates/*.html');!
    !
    for my $file (@files) {!
    my $content = file($file)->slurp;!
    my $has_japanese = $content =~ /[^[:ascii:]]+/;!
    ok ! $has_japanese, "$file ͸೔ຊޠΛؚ·ͳ͍";!
    }
    !
    !
    [% loc('blog.manage') %]!
    !
    !
    ϒϩά؅ཧ͕Ͱ͖·͢!
    !

    View full-size slide

  45. ՝୊4
    υΩϡϝϯτʹ
    ؾ͍ͮͯ΋Β͑ͳ͍

    View full-size slide

  46. ରࡦ4
    IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ

    υΩϡϝϯτͷ৔ॴΛ஌ΒͤΔͨΊʹɺ
    མͪΔςετΛ࡞Δ

    View full-size slide

  47. ՝୊5
    Nginxͷઃఆ͕
    ϦϑΝΫλϦϯά͞Εͳ͍
    ֬ೝ͕೉͍ͨ͠Ί

    View full-size slide

  48. ରࡦ5
    NginxΛҰ࣌తʹىಈͯ͠
    ςετΛ͢Δ

    View full-size slide

  49. IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ

    nginxͷproxyઃఆϑΝΠϧ΋
    ࣗಈςετ͠Α͏

    View full-size slide

  50. ػցʹ΍ΒͤΔ
    ਓ͕ؾΛ͚ͭΔ
    ՝୊
    ྫ) ςετ

    View full-size slide

  51. ೉͍͜͠ͱͯ͠ͳ͍
    ୯ମςετΑΓΉ͠Ζ؆୯

    View full-size slide

  52. ςετ͍Ζ͍Ζ͋ͬͯ
    ࢝Ίํ෼͔Βͳ͍

    View full-size slide

  53. ೔ʑͷ՝୊ΛςετͰ
    ղܾ͢Δͱ͜Ζ͔Β͸͡ΊΔ

    View full-size slide