| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Gives; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.006; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
24266
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
982
|
use Attribute::Handlers; |
|
|
1
|
|
|
|
|
6097
|
|
|
|
1
|
|
|
|
|
7
|
|
|
9
|
1
|
|
|
1
|
|
43
|
use Carp qw( croak ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
68
|
|
|
10
|
1
|
|
|
1
|
|
874
|
use Sub::Name; |
|
|
1
|
|
|
|
|
624
|
|
|
|
1
|
|
|
|
|
43
|
|
|
11
|
1
|
|
|
1
|
|
802
|
use Want; |
|
|
1
|
|
|
|
|
10302
|
|
|
|
1
|
|
|
|
|
127
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
969
|
use version; our $VERSION = qv("0.1.0"); |
|
|
1
|
|
|
|
|
8910
|
|
|
|
1
|
|
|
|
|
7
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
{ |
|
16
|
|
|
|
|
|
|
sub UNIVERSAL::Gives :ATTR { |
|
17
|
2
|
|
|
2
|
0
|
10880
|
my ($package, $glob, $ref, $attr, $data, $phase) = @_; |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
1
|
|
|
1
|
|
129
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
|
2
|
|
|
|
|
5
|
|
|
20
|
1
|
|
|
1
|
|
6
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
953
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
197
|
croak "Gives only applies to CODE" unless(UNIVERSAL::isa($ref,"CODE")); |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
4
|
my $symbol = *$glob{NAME}; |
|
25
|
1
|
50
|
|
|
|
4
|
my $pkg = (defined $package) ? $package : "main"; |
|
26
|
1
|
50
|
|
|
|
18
|
my @types = (UNIVERSAL::isa($data,"ARRAY")) ? @$data : ($data); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
5
|
*{$glob} = subname "${pkg}::${symbol}" => sub { |
|
29
|
5
|
100
|
|
5
|
|
10415
|
croak "sub ${symbol} returns ".join(", ",@types), |
|
|
|
|
|
5
|
|
|
|
|
30
|
|
|
|
|
|
|
unless (want(@types)); |
|
31
|
2
|
|
|
|
|
141
|
goto $ref; |
|
32
|
1
|
|
|
|
|
13
|
}; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
8
|
} |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
12
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Gives - Uses Want to add Perl types to subroutines |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=begin readme |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perl 5.6.0 is required, along with the following (possibly non-core) modules: |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Attribute::Handlers |
|
51
|
|
|
|
|
|
|
Sub::Name |
|
52
|
|
|
|
|
|
|
Want |
|
53
|
|
|
|
|
|
|
version |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Installation can be done using the traditional F or the |
|
58
|
|
|
|
|
|
|
newer F method . |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Using Makefile.PL: |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
perl Makefile.PL |
|
63
|
|
|
|
|
|
|
make test |
|
64
|
|
|
|
|
|
|
make install |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
(On Windows platforms you should use F instead.) |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Using Build.PL (if you have L installed): |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
perl Build.PL |
|
71
|
|
|
|
|
|
|
perl Build test |
|
72
|
|
|
|
|
|
|
perl Build install |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=end readme |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use Gives; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub my_func : Gives('LIST') { |
|
81
|
|
|
|
|
|
|
... |
|
82
|
|
|
|
|
|
|
return @some_list; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
@val = my_func(); # ok |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$val = my_func(); # causes an error |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This package uses L to add some rudimentary context checking to |
|
92
|
|
|
|
|
|
|
subroutines. It allows you to avoid using a subroutine or method in |
|
93
|
|
|
|
|
|
|
the wrong context. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
It I check the type returned by the function. If you want to |
|
96
|
|
|
|
|
|
|
enforce return types, use L. (You may be able |
|
97
|
|
|
|
|
|
|
to use both packages together.) |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
You specify the context using the Gives attribute: |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub my_func : Gives( @Contexts ) { |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
where C<@Contexts> is a list of contexts accepted by L (see the |
|
105
|
|
|
|
|
|
|
package documentation for valid contexts). |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 CAVEATS AND KNOWN ISSUES |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This is an experimental package. There may be bugs. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
There may be incompatabilities with L. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Want |
|
116
|
|
|
|
|
|
|
Attribute::Context |
|
117
|
|
|
|
|
|
|
Sub::Context |
|
118
|
|
|
|
|
|
|
Attribute::Signature |
|
119
|
|
|
|
|
|
|
Attribute::Types |
|
120
|
|
|
|
|
|
|
Variable::Strict::Types |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Robert Rothenberg |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 Suggestions and Bug Reporting |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Feedback is always welcome. Please use the CPAN Request Tracker at |
|
129
|
|
|
|
|
|
|
L to submit bug reports. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 LICENSE |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Copyright (c) 2006 Robert Rothenberg. All rights reserved. |
|
134
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
135
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |