Kusarigama/Hook/OnCommand.pm

filter: Statementstmt 100% 15 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 19 / 19 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Kusarigama/Hook/OnAdd.pm ↑ Summary Kusarigama/Hook/OnExit.pm »
1 package Taskwarrior::Kusarigama::Hook::OnCommand;
2 9 our $AUTHORITY = 'cpan:YANICK';
3 #ABSTRACT: Role for plugins implementing custom commands
4 9 $Taskwarrior::Kusarigama::Hook::OnCommand::VERSION = '0.10.0';
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has command_name => (
11 is => 'ro',
12 default => sub {
13 lc(
14 1 ▶ ( lcfirst ref($_[0]) =~ s/^.*::Command:://r )
Subroutine __ANON__: called CC=1 SCAR=0.0
15 =~ s/(?=[A-Z])/-/gr
16 );
17 },
18 9 );
19  
20 9 requires 'on_command';
21  
22 9 1;
23  
24 __END__
25  
26 =pod
27  
28 =encoding UTF-8
29  
30 =head1 NAME
31  
32 Taskwarrior::Kusarigama::Hook::OnCommand - Role for plugins implementing custom commands
33  
34 =head1 VERSION
35  
36 version 0.10.0
37  
38 =head1 SYNOPSIS
39  
40 package Taskwarrior::Kusarigama::Plugin::Command::Foo;
41  
42 use Moo;
43  
44 extends 'Taskwarrior::Kusarigama::Hook';
45  
46 with 'Taskwarrior::Kusarigama::Hook::OnCommand';
47  
48 sub on_command {
49 say "running foo";
50 }
51  
52 1;
53  
54 =head1 DESCRIPTION
55  
56 Role consumed by plugins implementing a custom command.
57  
58 Requires that a C<on_command> is implemented.
59  
60 By default, the command name is the name of the package minus
61 its
62 C<Taskwarrior::Kusarigama::Plugin::Command::> prefix,
63 but it can be modified via the C<command_name> attribute.
64  
65 package MyCustom::Command;
66  
67 use Moo;
68  
69 extends 'Taskwarrior::Kusarigama::Hook';
70 with 'Taskwarrior::Kusarigama::Hook::OnCommand';
71  
72 # will intercept `task custom-command`
73 has '+command_name' => (
74 default => sub { return 'custom-command' },
75 );
76  
77 sub on_command { ... };
78  
79 =head1 AUTHOR
80  
81 Yanick Champoux <yanick@cpan.org>
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 This software is copyright (c) 2018, 2017 by Yanick Champoux.
86  
87 This is free software; you can redistribute it and/or modify it under
88 the same terms as the Perl 5 programming language system itself.
89  
90 =cut
« Kusarigama/Hook/OnAdd.pm ↑ Summary Kusarigama/Hook/OnExit.pm »