blib/lib/Syntax/Feature/Method.pm

filter: Statementstmt 100% 29 / 29 Branchbran n/a Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 45 / 45 CC 3 SCAR 4.4
CC
3
Cov
100%
install
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # ABSTRACT: Provide a method keyword
5  
6 package Syntax::Feature::Method;
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Syntax::Feature::Method::VERSION = '0.001';
9 }
10  
11 1 ▶use Method::Signatures::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use B::Hooks::EndOfScope;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 $Carp::Internal{ +__PACKAGE__ }++;
18  
19 4 ▶sub install {
Subroutine install: called CC=3 SCAR=11.0
Pod documented
20 4 my ($class, %args) = @_;
21  
22 4 my $target = $args{into};
23 4 ▶ my $name = $args{options}{ -as } || 'method';
Condition100%2/2
$args{'options'}{'-as'} || 'method'
l!l
22
MC/DC100%1/1
$args{'options'}{'-as'} || 'method'
$args{'options'}{'-as'}
Truth table100%2/2
A
A= $args{'options'}{'-as'}
Aresult
11
00
24 4 ▶ my $invocant = $args{options}{ -invocant } || '$self';
Condition100%2/2
$args{'options'}{'-invocant'} || '$self'
l!l
13
MC/DC100%1/1
$args{'options'}{'-invocant'} || '$self'
$args{'options'}{'-invocant'}
Truth table100%2/2
A
A= $args{'options'}{'-invocant'}
Aresult
11
00
25  
26 # install keyword
27 4 Method::Signatures::Simple->import(
28 into => $target,
29 name => $name,
30 invocant => $invocant,
31 );
32  
33 # remove runtime handler at end of scope
34 4 ▶ on_scope_end {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 4 namespace::clean->clean_subroutines($target, $name);
36 4 };
37  
38 4 return 1;
39 }
40  
41 1 1;
42  
43  
44  
45 =pod
46  
47 =head1 NAME
48  
49 Syntax::Feature::Method - Provide a method keyword
50  
51 =head1 VERSION
52  
53 version 0.001
54  
55 =head1 SYNOPSIS
56  
57 use syntax 'method';
58  
59 method foo ($n) { $n * $self->bar }
60  
61 my $method = method ($msg) {
62 print "$msg\n";
63 };
64  
65 =head1 DESCRIPTION
66  
67 This module will install the L<Method::Signatures::Simple> syntax extension
68 into the requesting namespace.
69  
70 You can import the keyword multiple times under different names with different
71 options:
72  
73 use syntax
74 'method',
75 'method' => {
76 -as => 'classmethod',
77 -invocant => '$class',
78 };
79  
80 =head1 OPTIONS
81  
82 =head2 -as
83  
84 use syntax method => { -as => 'provide' };
85  
86 provide addition ($n, $m) { $n + $m }
87  
88 The C<-as> keyword allows you to install the keyword under a different name.
89 This is especially useful if you want a separate keyword for class methods with
90 a different L<invocant|/-invocant>.
91  
92 =head2 -invocant
93  
94 use syntax method => { -invocant => '$me' };
95  
96 method sum { $me->foo + $me->bar }
97  
98 Allows you to set a different default invocant. Useful if you want to import
99 a second keyword for class methods that has a C<$class> invocant.
100  
101 =head1 METHODS
102  
103 =head2 install
104  
105 Called by the L<syntax> dispatcher to install the exntension into the
106 requesting package.
107  
108 =head1 SEE ALSO
109  
110 L<syntax>,
111 L<Method::Signatures::Simple>
112  
113 =head1 BUGS
114  
115 Please report any bugs or feature requests to bug-syntax-feature-method@rt.cpan.org or through the web interface at:
116 http://rt.cpan.org/Public/Dist/Display.html?Name=Syntax-Feature-Method
117  
118 =head1 AUTHOR
119  
120 Robert 'phaylon' Sedlacek <rs@474.at>
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is copyright (c) 2010 by Robert 'phaylon' Sedlacek.
125  
126 This is free software; you can redistribute it and/or modify it under
127 the same terms as the Perl 5 programming language system itself.
128  
129 =cut
130  
131  
132 __END__
↑ Summary