line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Dot.pm 28 2007-10-29 17:35:27Z asksol $ |
2
|
|
|
|
|
|
|
# $Source: /opt/CVS/Getopt-LL/lib/Class/Dot.pm,v $ |
3
|
|
|
|
|
|
|
# $Author: asksol $ |
4
|
|
|
|
|
|
|
# $HeadURL: https://class-dot.googlecode.com/svn/class-dot/lib/Class/Dot.pm $ |
5
|
|
|
|
|
|
|
# $Revision: 28 $ |
6
|
|
|
|
|
|
|
# $Date: 2007-10-29 18:35:27 +0100 (Mon, 29 Oct 2007) $ |
7
|
|
|
|
|
|
|
package Class::Dot::Types; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
150
|
|
10
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
115
|
|
11
|
4
|
|
|
4
|
|
20
|
use version qw(qv); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
20
|
|
12
|
4
|
|
|
4
|
|
226
|
use 5.006000; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
159
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
21
|
use Carp qw(croak); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1491
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = qv('1.5.0'); |
17
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ASKSH'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @STD_TYPES = qw( |
20
|
|
|
|
|
|
|
isa_String isa_Int isa_Array isa_Hash |
21
|
|
|
|
|
|
|
isa_Data isa_Object isa_Code isa_File |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @EXPORT_OK = @STD_TYPES; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %EXPORT_CLASS = ( |
27
|
|
|
|
|
|
|
':std' => [@EXPORT_OK], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our %__TYPEDICT__ = ( |
31
|
|
|
|
|
|
|
'Array' => \&isa_Array, |
32
|
|
|
|
|
|
|
'Code' => \&isa_Code, |
33
|
|
|
|
|
|
|
'Data' => \&isa_Data, |
34
|
|
|
|
|
|
|
'File' => \&isa_File, |
35
|
|
|
|
|
|
|
'Hash' => \&isa_Hash, |
36
|
|
|
|
|
|
|
'Int' => \&isa_Int, |
37
|
|
|
|
|
|
|
'Object' => \&isa_Object, |
38
|
|
|
|
|
|
|
'String' => \&isa_String, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub import { ## no critic |
42
|
4
|
|
|
4
|
|
8
|
my $this_class = shift; |
43
|
4
|
|
|
|
|
8
|
my $caller_class = caller; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
7
|
my $export_class; |
46
|
|
|
|
|
|
|
my @subs; |
47
|
4
|
|
|
|
|
10
|
for my $arg (@_) { |
48
|
4
|
50
|
|
|
|
26
|
if ($arg =~ m/^:/xms) { |
49
|
4
|
50
|
|
|
|
16
|
croak( 'Only one export class can be used. ' |
50
|
|
|
|
|
|
|
."(Used already: [$export_class] now: [$arg])") |
51
|
|
|
|
|
|
|
if $export_class; |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
15
|
$export_class = $arg; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
0
|
push @subs, $arg; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my @subs_to_export |
61
|
4
|
|
|
|
|
17
|
= $export_class && $EXPORT_CLASS{$export_class} |
62
|
4
|
50
|
33
|
|
|
41
|
? (@{ $EXPORT_CLASS{$export_class} }, @subs) |
63
|
|
|
|
|
|
|
: @subs; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
4
|
|
22
|
no strict 'refs'; ## no critic; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
555
|
|
66
|
4
|
|
|
|
|
10
|
for my $sub_to_export (@subs_to_export) { |
67
|
32
|
|
|
|
|
54
|
_install_sub_from_class($this_class, $sub_to_export => $caller_class); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
1394
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _install_sub_from_class { |
74
|
32
|
|
|
32
|
|
42
|
my ($pkg_from, $sub_name, $pkg_to) = @_; |
75
|
32
|
|
|
|
|
95
|
my $from = join q{::}, ($pkg_from, $sub_name); |
76
|
32
|
|
|
|
|
44
|
my $to = join q{::}, ($pkg_to, $sub_name); |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
4
|
|
17
|
no strict 'refs'; ## no critic |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1923
|
|
79
|
32
|
|
|
|
|
34
|
*{$to} = *{$from}; |
|
32
|
|
|
|
|
114
|
|
|
32
|
|
|
|
|
66
|
|
80
|
|
|
|
|
|
|
|
81
|
32
|
|
|
|
|
71
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub isa_String { ## no critic |
86
|
12
|
|
|
12
|
1
|
40
|
my ($default_value) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return sub { |
89
|
2
|
100
|
|
2
|
|
12
|
return $default_value |
90
|
|
|
|
|
|
|
if defined $default_value; |
91
|
1
|
|
|
|
|
3
|
return; |
92
|
12
|
|
|
|
|
67
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub isa_Int { ## no critic |
96
|
5
|
|
|
5
|
1
|
21
|
my ($default_value) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return sub { |
99
|
2
|
100
|
|
2
|
|
10
|
return $default_value |
100
|
|
|
|
|
|
|
if defined $default_value; |
101
|
1
|
|
|
|
|
6
|
return; |
102
|
5
|
|
|
|
|
42
|
}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub isa_Array { ## no critic |
106
|
5
|
|
|
5
|
1
|
120
|
my @default_values = @_; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return sub { |
109
|
|
|
|
|
|
|
return scalar @default_values |
110
|
3
|
100
|
|
3
|
|
21
|
? \@default_values |
111
|
|
|
|
|
|
|
: [ ]; |
112
|
5
|
|
|
|
|
35
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub isa_Hash { ## no critic |
116
|
7
|
|
|
7
|
1
|
27
|
my %default_values = @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return sub { |
119
|
3
|
100
|
|
3
|
|
26
|
return scalar keys %default_values |
120
|
|
|
|
|
|
|
? \%default_values |
121
|
|
|
|
|
|
|
: { }; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# have to test if there are any entries in the hash |
124
|
|
|
|
|
|
|
# so we return a new anonymous hash if it ain't. |
125
|
7
|
|
|
|
|
37
|
}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub isa_Data { ## no critic |
129
|
6
|
|
|
6
|
1
|
903
|
my ($default_value) = @_; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
return sub { |
132
|
1
|
50
|
|
1
|
|
6
|
return $default_value |
133
|
|
|
|
|
|
|
if defined $default_value; |
134
|
1
|
|
|
|
|
4
|
return; |
135
|
6
|
|
|
|
|
37
|
}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub isa_Code (;&;) { ## no critic |
139
|
2
|
|
|
2
|
1
|
7
|
my $code_ref = shift; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
return sub { |
142
|
2
|
100
|
|
2
|
|
16
|
return defined $code_ref ? $code_ref : sub { }; |
|
0
|
|
|
|
|
0
|
|
143
|
|
|
|
|
|
|
} |
144
|
2
|
|
|
|
|
11
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub isa_File { ## no critic |
147
|
2
|
|
|
2
|
1
|
7
|
my $filehandle = shift; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
return sub { |
150
|
2
|
100
|
|
2
|
|
12
|
if (defined $filehandle) { |
151
|
1
|
|
|
|
|
8
|
return $filehandle; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
1
|
|
|
|
|
1033
|
require FileHandle; |
155
|
1
|
|
|
|
|
14666
|
return FileHandle->new( ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
2
|
|
|
|
|
9
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub isa_Object { ## no critic |
161
|
2
|
|
|
2
|
1
|
4
|
my $class = shift; |
162
|
2
|
|
|
|
|
2
|
my %opts; |
163
|
2
|
50
|
|
|
|
7
|
if (!scalar @_ % 2) { |
164
|
2
|
|
|
|
|
5
|
%opts = @_; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
return sub { |
167
|
2
|
100
|
|
2
|
|
10
|
return if not defined $class; |
168
|
1
|
50
|
|
|
|
19
|
if ($opts{auto}) { |
169
|
1
|
|
|
|
|
8
|
return $class->new(); |
170
|
|
|
|
|
|
|
} |
171
|
0
|
|
|
|
|
|
return; |
172
|
2
|
|
|
|
|
22
|
}; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |