# Perl lang snippets {{{
snippet pm:strict
options head
    package ${1:`substitute(substitute(expand('%'), '\(^lib\/\|\.pm$\)', '', 'g'), '/', '::', 'g')`};
    use strict;
    use warnings;
    use utf8;

    ${0}
    
    1;

snippet pl
options head
    #! /usr/bin/env perl
    use strict;
    use warnings;
    use utf8;

    ${0}

snippet pm:5.014
options head
    package ${1:`substitute(substitute(expand('%'), '\(^lib\/\|\.pm$\)', '', 'g'), '/', '::', 'g')`};
    use 5.014;
    use warnings;
    use utf8;

    ${0}
    
    1;

snippet sub
alias s
    sub ${1} {
        ${0}
    }

snippet new
alias n
    sub new {
        ${0}
    return bless {
    }, $class;
  }

snippet class
alias c
    my ($class) = @_;
    ${0}

snippet class_arg
alias ca
    my ($class, ${1}) = @_;
    ${0}

snippet self
alias s
    my ($self) = @_;
    ${0}

snippet self_arg
alias sa
    my ($self, ${1}) = @_;
    ${0}

snippet no_critic
alias noc
    ## no critic (${1:#:policy_name})

snippet qw/
    qw/${0}/

snippet qw|
    qw|${0}|

snippet qw(
    qw(${0})

snippet qr/
    qr/${0}/xms

snippet qr(
    qr(${0})xms

snippet unless
    unless (${1}) {
        ${0}
    }

snippet foreach
    foreach my ${1} (${2}) {
        ${0}
    }

snippet while
    while (my (${1:#:$key}, ${2:#:$value}) = each(${3:#:HASHREF or HASH})) {
        ${0}
    }
# }}}


snippet val
alias v
    my ($self, @args) = @_;
    state $rule = Data::Validator->new(
        ${0}
    );

    my $validated = $rule->validate(@args);


snippet export
alias exp
    use Exporter 'import';
    our @EXPORT_OK = qw {
        ${0}
    };


# Debugging snippets {{{
snippet dump
alias d
    use Data::Dumper;
    $Data::Dumper::Deparse = 1;
    $Data::Dumper::Indent = 1;
    warn Dumper ${0};

snippet dumpmarker
alias dm
    use Data::Dumper;
    $Data::Dumper::Deparse = 1;
    warn '<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $0';
    warn Dumper ${0};
    warn '>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $0';
# }}}


# General test snippets {{{
snippet mock_module
    my $mock_module = Test::MockModule->new('${1}');
    $mock_module->mock('${2:#:subroutine_name}', sub { ${3} });


snippet mock_obj
    my $mock_obj = Test::MockObject->new();
    $mock_obj->mock('${1:#:subroutine_name}', sub { ${2} });
# }}}


# Test::More snippets {{{
snippet test:more
options head
alias t
    #! /use/bin/env perl
    use strict;
    use warnings;
    use utf8;
    use Test::More;
    use Test::Deep;
    use Test::Exception;

    ${0}

    done_testing;

snippet subtest
alias st
    subtest '${1}' => sub {
        ${0}
    };

snippet use_ok:more
alias uok
    BEGIN {
        use_ok qw/${0}/;
    }

snippet can_ok
alias cok
    can_ok(
        '${1:class_name}',
        qw/
            ${0}
        /
    );

snippet ok_diag
alias okd
    ok(${1:#:target}, '${2:#:message}') or diag explain $1;${0}

snippet is_diag
alias isd
    is(${1:#:actual}, ${2:#:expected}, '${3:#:message}') or diag explain $1;${0}

snippet cmp_deeply_diag
alias cdd
    cmp_deeply(${1:#:actual}, ${2:#:expected}, '${3:#:message}') or diag explain $1;${0}

snippet plan_skip
alias skipp
    plan skip_all => '${1:#:reason}';
# }}}


# Test::Kantan snippets {{{
snippet test:kantan
options head
    #! /use/bin/env perl
    use strict;
    use warnings;
    use utf8;
    use Test::Kantan;
    use Test::MockModule;
    use Test::MockObject;

    ${0}

    done_testing;

snippet describe
alias desc
    describe '${1}', sub {
        ${0}
    };

snippet it
    it '${1}', sub {
        ${0}
    };

snippet should
    it 'should ${1}', sub {
        ${0}
    };

snippet context
    context '${1}', sub {
        ${0}
    };

snippet when
    context 'when ${1}', sub {
        ${0}
    };
#
# snippet setup
# alias su
#     setup {
#         ${0}
#     };

snippet teardown
alias td
    teardown {
        ${0}
    };

snippet before_each
alias be
    before_each {
        ${0}
    };

snippet after_each
alias ae
    after_each {
        ${0}
    };

snippet ok
    ok {${0}};

snippet use_ok:kantan
    it 'should be loaded successfully', sub {
        ok { require ${1:`substitute(substitute(expand('%'), '\(^t\/lib\/\|\.t$\)', '', 'g'), '/', '::', 'g')`} };
    };
    ${0}

snippet setup
    setup {
        require ${1:#:FQN};
        $1->import(${2:#:LIST});
    };
    ${0}

snippet expect
alias exp
    expect(${1})->${0}

snippet not
    not()${0}

snippet to_be_defined
    to_be_defined()${0}

snippet to_be_truthy
    to_be_truthy()${0}

snippet to_be_falsey
    to_be_falsey()${0}

snippet to_equal
    to_equal(${1})${0}

snippet to_be
    to_be(${1})${0}

snippet to_throw
    to_throw()${0}

snippet to_match
    to_match(${1})${0}

snippet to_be_a
    to_be_a(${1})${0}

snippet to_be_a_bag_of
    to_be_a_bag_of(${1})${0}

snippet to_be_a_set_of
    to_be_a_set_of(${1})${0}

snippet to_be_a_super_bag_of
    to_be_a_super_bag_of(${1})${0}

snippet to_be_a_super_set_of
    to_be_a_super_set_of(${1})${0}

snippet to_be_a_super_hash_of
    to_be_a_super_hash_of(${1})${0}

snippet to_be_a_sub_bag_of
    to_be_a_sub_bag_of(${1})${0}

snippet to_be_a_sub_set_of
    to_be_a_sub_set_of(${1})${0}

snippet to_be_a_sub_hash_of
    to_be_a_sub_hash_of(${1})${0}

snippet skip
    skip_all;
# }}}


# POD snippets {{{
snippet podmethod
alias podm
    =head3 C<<${1:#:method_name}>>

    =head4 PARAMETERS

    =over 4

    =item C<>

    =back

    =head4 RETURN VALUE

    =over 4

    =item C<>

    =back

snippet podhead
alias podh
    =encoding utf-8

    =head1 NAME

    ${1:#:package_name}

    =head1 SYNOPSIS

    ${0}

    =head1 DESCRIPTION

    =head1 CONFIGURATION AND ENVIRONMENT

    =head1 INTERFACE

    =head2 CLASSMETHODS

    =head2 METHODS

    =cut

snippet podtail
alias podt
    =head1 SEE ALSO

    =head1 BUGS AND LIMITATION

    このモジュールには既知のバグは含まれていません。
        何か問題があった場合は修正して頂くか、 L</AUTHOR> にご連絡ください。

    =head1 AUTHOR

    ${1:`system('git config user.name')`} (${2:`system('git config user.email')`})

    =cut
# }}}

# vim: fdm=marker