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

Hokkaido.pm#11

akiym
December 28, 2013

 Hokkaido.pm#11

Cocoa module, perl-5.19

akiym

December 28, 2013
Tweet

More Decks by akiym

Other Decks in Technology

Transcript

  1. ࠓ೥ॻ͍ͨ
    1FSMͷίʔυͷৼΓฦΓ
    )PLLBJEPQN
    !BLJZN

    View Slide

  2. NF
    w !BLJZN
    w
    w TFDDBNQ ZBQDBTJB
    w 4&$$0/ࡳຈେձ༏উ

    View Slide

  3. DUGLBUTVEPOPSH

    View Slide

  4. $1"/HJUIVC

    View Slide

  5. $1"/
    w "OZ&WFOU4,,4FSW
    w $PDPB/FUXPSL$IBOHF
    w 3FHFYQ7FSCBM&YQSFTTJPOT

    View Slide

  6. $1"/
    w "OZ&WFOU4,,4FSW
    w $PDPB/FUXPSL$IBOHF
    w 3FHFYQ7FSCBM&YQSFTTJPOT

    View Slide

  7. View Slide

  8. ϑλΛดͯ͡ˠ։͘ͷ8J'JͷεΠονΛ
    ར༻ͯ͠ࠂന͞ΕΔ

    View Slide



  9. View Slide

  10. (JUIVC
    w .BD,FZCPBSE-&%
    $PDPB%JDUJPOBSZ4FSWJDFT Q6OB[V$IBO
    $PDPB(VJ5FTU "OZ&WFOU-FBQ.PUJPO
    "NPO8FC%JTQBUDIFS%7
    5FYU1JDP5FNQMBUF
    888'$7JEFP%PXOMPBE
    (BNFT1JDSPTT 5FYU$IJOFTF/VNFSBMT+"
    *SPI

    View Slide

  11. લճͷ)PLLBJEPQN
    Ͱ࿩͠·ͨ͠

    View Slide

  12. View Slide


  13. View Slide

  14. $PDPBNPEVMF

    View Slide

  15. w ͳͥ$PDPBϞδϡʔϧΛॻ͘ͷ͔ʁ
    w $PDPB"1*Λ৮Γ͍͔ͨΒ
    w 1FSMͰ.BDΞϓϦ͡Όͳͯ͘ɺ.BDͷػೳʹ
    ΞΫηε͍͚ͨͩͩ͠͠ɺ୯ମϞδϡʔϧʹ͠
    ͍ͯͬͨ΄͏͕ΈΜͳ͕޾ͤ
    w ͱUZQFTUFS͞Μ͕ݴ͍ͬͯͨ BHSFF

    View Slide

  16. $PDPBNPEVMFͷ
    ࡞Γํ

    View Slide

  17. w ࠷ۙ
    w 946#Ͱॻ͚ΔΑ͏ʹͳͬͨͷͰ௒ઈศར
    w ֵ໋
    w $PDPB(SPXM΍$PDPB4LZQF͸໘౗ͳ͜ͱΛ
    ͍ͯ͠Δ
    w YTVCQQ͕ੜ੒͢ΔDΛखͰॻ͘Α͏ͳ͜ͱ

    View Slide

  18. NJOJMOFX
    w .JOJMMBͰ࡞੒͢Δ
    w ANJOJMOFXQ94.PEVMFA
    w CVJMEFS.Z#VJMEFSQNΛ࡞੒
    w IUUQTPIIBUFOBCMPHDPNFOUSZ

    View Slide

  19. CVJMEFS.Z#VJMEFSQN
    package builder::MyBuilder;
    use strict;
    use warnings;
    use parent qw(Module::Build);
    use File::Copy;
    !
    sub new {
    my ($self, %args) = @_;
    $self->SUPER::new(
    %args,
    extra_compiler_flags => ['-Wall'],
    extra_linker_flags => ['-framework', 'Foundation'],
    );
    }
    GSBNFXPSLͷϦϯΫ

    View Slide

  20. CVJMEFS.Z#VJMEFSQN
    sub compile_c {
    my ($self, $file, %args) = @_;
    !
    (my $m_file = $file) =~ s/\.c$/.m/;
    move($file, $m_file) or die $!;
    !
    $self->SUPER::compile_c($m_file, %args);
    }
    !
    1;

    View Slide

  21. NJOJMUPNM
    [build]
    build_class = "builder::MyBuilder"

    View Slide

  22. w YTʹΰϦΰϦͱॻ͍͍ͯ͘
    w NBLF͢ΔͱN͕ੜ੒͞ΕΔ
    w HJUJHOPSFʹlib/Foo.mͷΑ͏ʹ௥Ճ͓ͯ͘͠

    View Slide

  23. w ී௨ͷ94ͱಉ͡Α͏ʹॻ͚·͢
    w $PDPBˠ1FSM 1FSMˠ$PDPBͷσʔλͷม׵
    ʹؾΛ͚ͭΕ͹͍͍͚ͩͰ͢
    w ͦΕҎ֎͸ͨͩͷ94
    w Ͳ͏΍Ε͹͍͍Μͩʜͱ͍͏ͱ͖ʹ͸
    w UZQFTUFS͞Μ΍TPI͞ΜͷSFQPTJUPSZΛ

    ࢀߟʹ͢Δ

    View Slide

  24. σʔλͷม׵
    w IUUQXXXTMJEFTIBSFOFUUZQFTUFSIBDLJOHNBDPTYDPDPBBQJGSPN
    QFSM
    w IUUQTHJUIVCDPNTPI$PDPB/4%JTUSJCVUFE/PUJpDBUJPO$FOUFS
    CMPCNBTUFSOT@EJTUSJCVUFE@OPUJpDBUJPO@DFOUFSN
    • nsnumber_to_sv(), ns_to_sv()

    View Slide

  25. σʔλͷม׵
    # e.g. NSString → SVPV
    !
    SV* sv = sv_2mortal(newSV(0));
    sv_setpv(sv, [str UTF8String]);

    View Slide

  26. Ͱ

    View Slide

  27. .BD,FZCPBSE-&%
    w ͱ͍͏ϞδϡʔϧΛ࡞Γ·ͨ͠
    w IUUQHPPHMFNBDCMPHTQPUKQ
    NBOJQVMBUJOHLFZCPBSEMFETUISPVHIIUNM
    w ͜ΕΛͦͷ··࣋ͬͯ͘Δ͜ͱʹ
    w ͳͷͰɺઆ໌͢Δ͜ͱ͕͋Γ·ͤΜ

    View Slide

  28. HJUIVCDPNBLJZN.BD,FZCPBSE-&%

    View Slide

  29. JTTVF
    w .JOJMMBͰ%FWFM"TTFSU04తͳ͜ͱΛ͍ͨ͠
    w CVJMEFS.Z#VJMEFSQNIBDL
    • die 'OS unsupported' unless ($^O eq 'darwin');

    View Slide


  30. View Slide

  31. QFSM

    View Slide

  32. MBUFTUSFMFBTF
    QFSM

    View Slide

  33. QFSMEFMUBΛோΊΔ

    View Slide

  34. IBTITMJDFTZOUBY
    w %hash{…} %array[...]
    w LFZWBMVF JOEFYWBMVF
    ͷϦετΛฦ͠·͢
    w ͍͚ͯΔ

    View Slide

  35. IBTITMJDFTZOUBY
    my %h = (
    blonk => 2,
    foo => 3,
    squink => 5,
    bar => 8,
    );
    my %subset = %h{qw/foo bar/};
    # => (foo => 3, bar => 8)

    View Slide

  36. IBTITMJDFTZOUBY
    my @a = "a".."z";
    my @list = %a[3,4,6];
    # => (3, "d", 4, "e", 6, "g")

    View Slide

  37. QPTUpYEFSFGFSFODJOH
    w ޙஔσϦϑΝϨϯε
    w !BˠB!
    w ෳࡶͳσʔλߏ଄Λૢ࡞͢Δͱ͖ʹศར
    w TMJDFͱ૊Έ߹ΘͤΔ͜ͱ͕Ͱ͖Δ

    View Slide

  38. QPTUpYEFSFGFSFODJOH
    no warnings 'experimental::postderef';
    use feature qw/postderef/;
    !
    my $r = [1, 2, 3];
    my @a = @$r;
    my @b = $r->@*;

    View Slide

  39. σʔλߏ଄
    my $foo = {
    bar => {
    baz => {
    a => 1,
    b => 2,
    c => 3,
    }
    }
    };
    !

    View Slide

  40. σʔλߏ଄
    my $foo = {
    bar => {
    baz => {
    a => 1,
    b => 2,
    c => 3,
    }
    }
    };
    !
    my @ab = @{$foo->{bar}{baz}}{qw/a b/}; # => [1, 2]
    ஍ࠈͬΆ͍

    View Slide

  41. σʔλߏ଄
    my $foo = {
    bar => {
    baz => {
    a => 1,
    b => 2,
    c => 3,
    }
    }
    };
    !
    my @ab = $foo->{bar}{baz}->@{qw/a b/}; # => [1, 2]

    View Slide

  42. :PV5VCF%BUB"1*
    $VAR1 = {
    'fmt' => '36',
    'fmt_list' => [
    '36',
    '18',
    '5',
    '43',
    '17'
    ],
    'resolution' => '320x240',
    'suffix' => 'flv',
    'title' => 'HE-MAN HEYEAYEA SONG FOR 10 HOURS',
    'user' => undef,
    'video_id' => 'eh7lp9umG2I',
    'video_url' => ...,
    'video_url_map' => {
    '17' => {
    'fmt' => '17',
    'resolution' => '176x144',
    'suffix' => '3gp',
    'url' => ...
    },
    '18' => {
    'fmt' => '18',
    'resolution' => '320x240',

    View Slide

  43. ࠓ·Ͱ
    # video_url_mapから各フォーマットのデータを
    # ひっぱってくる
    !
    my @data = @{$data->{video_url_map}}{@{$data->{fmt_list}}};

    View Slide

  44. # video_url_mapから各フォーマットのデータを
    # ひっぱってくる
    !
    my @data = @{$data->{video_url_map}}{@{$data->{fmt_list}}};
    ࠓ·Ͱ

    View Slide

  45. QPTUEFSFG
    # video_url_mapから各フォーマットのデータを
    # ひっぱってくる
    !
    my @data = $data->{video_url_map}->@{$data->{fmt_list}->@*};

    View Slide

  46. w QSPUPUZQFBUUSJCVUF
    w sub foo($$){}ˠsub foo : prototype($$){}
    w Perl 5.19.2から $!が decodeされる
    w http://d.hatena.ne.jp/syohex/
    20131227/1388149250

    View Slide

  47. 1FSM2VJ[

    View Slide

  48. ͜ͷίʔυ͸ಈ͘ʁ
    # メモリは十分にあるとする
    # perl-5.18.1 (64bit)
    !
    my @a;
    $a[2**31] = 1;
    !
    # =>

    View Slide

  49. ͜ͷίʔυ͸ಈ͘ʁ
    # メモリは十分にあるとする
    # perl-5.18.1 (64bit)
    !
    my @a;
    $a[2**31] = 1;
    !
    # => Modification of non-creatable array
    value attempted, subscript -2147483648
    ಈ͔ͳ͍

    View Slide

  50. QFSMҎ߱ͳΒ
    my @a;
    $a[2**31] = 1;
    !
    # On 64-bit platforms, the internal array
    functions now use 64-bit offsets, allowing
    Perl arrays to hold more than 2**31 elements,
    if you have the memory available.

    View Slide

  51. EFQSFDBUJPOT
    w $(*QN

    w ΍ͬͱ ɾТɾʆ

    View Slide

  52. w .PEVMF1MVHHBCMF
    w 0CKFDU"DDFTTPS
    w 1PE-B5F9
    w 5FSN6*
    w 5FYU4PVOEFY
    SFNPWFENPEVMFT
    w "SDIJWF&YUSBDU
    w #-JOU
    w $1"/1-64
    w 'JMF$IFDL5SFF
    w -PH.FTTBHF

    View Slide

  53. ·ͱΊ
    w ͪΐͬͱͨ͠$PDPBNPEVMFͷ࡞Γํ
    w QFSM
    w IBTITMJDFTZOUBY QPTUpYEFSFGFSFODJOH

    View Slide