line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MouseX::NativeTraits::MethodProvider::Str; |
2
|
2
|
|
|
2
|
|
1474
|
use Mouse; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
3
|
2
|
|
|
2
|
|
605
|
use Mouse::Util::TypeConstraints (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
3930
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends qw(MouseX::NativeTraits::MethodProvider); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub generate_append { |
8
|
10
|
|
|
10
|
1
|
169
|
my($self) = @_; |
9
|
10
|
|
|
|
|
29
|
my $reader = $self->reader; |
10
|
10
|
|
|
|
|
20
|
my $writer = $self->writer; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
return sub { |
13
|
42
|
|
|
42
|
|
13393
|
my($instance, $value) = @_; |
|
|
|
|
242
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
192
|
|
|
|
14
|
42
|
100
|
|
|
|
145
|
if(@_ != 2) { |
15
|
20
|
|
|
|
|
84
|
$self->argument_error('append', 2, 2, scalar @_); |
16
|
|
|
|
|
|
|
} |
17
|
22
|
50
|
|
|
|
54
|
defined($value) or $self->meta->throw_error( |
18
|
|
|
|
|
|
|
"The argument passed to append must be a string"); |
19
|
22
|
|
|
|
|
188
|
$writer->( $instance, $reader->( $instance ) . $value ); |
20
|
10
|
|
|
|
|
85
|
}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub generate_prepend { |
24
|
10
|
|
|
10
|
1
|
168
|
my($self) = @_; |
25
|
10
|
|
|
|
|
32
|
my $reader = $self->reader; |
26
|
10
|
|
|
|
|
23
|
my $writer = $self->writer; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return sub { |
29
|
20
|
|
|
20
|
|
12008
|
my($instance, $value) = @_; |
30
|
20
|
50
|
|
|
|
69
|
if(@_ != 2) { |
31
|
0
|
|
|
|
|
0
|
$self->argument_error('prepend', 2, 2, scalar @_); |
32
|
|
|
|
|
|
|
} |
33
|
20
|
50
|
|
|
|
53
|
defined($value) or $self->meta->throw_error( |
34
|
|
|
|
|
|
|
"The argument passed to prepend must be a string"); |
35
|
20
|
|
|
|
|
136
|
$writer->( $instance, $value . $reader->( $instance ) ); |
36
|
10
|
|
|
|
|
72
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub generate_replace { |
40
|
10
|
|
|
30
|
1
|
162
|
my($self) = @_; |
41
|
10
|
|
|
|
|
25
|
my $reader = $self->reader; |
42
|
10
|
|
|
|
|
24
|
my $writer = $self->writer; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return sub { |
45
|
70
|
|
|
90
|
|
19047
|
my( $instance, $regexp, $replacement ) = @_; |
46
|
70
|
50
|
|
|
|
201
|
if(@_ != 3) { |
47
|
0
|
|
|
|
|
0
|
$self->argument_error('replace', 3, 3, scalar @_); |
48
|
|
|
|
|
|
|
} |
49
|
70
|
100
|
100
|
|
|
477
|
( Mouse::Util::TypeConstraints::Str($regexp) |
50
|
|
|
|
|
|
|
|| Mouse::Util::TypeConstraints::RegexpRef($regexp) ) |
51
|
|
|
|
|
|
|
or $self->meta->throw_error( |
52
|
|
|
|
|
|
|
"The first argument passed to replace must be a string" |
53
|
|
|
|
|
|
|
. " or regexp reference"); |
54
|
60
|
|
|
|
|
157
|
my $v = $reader->( $instance ); |
55
|
|
|
|
|
|
|
|
56
|
60
|
100
|
|
|
|
351
|
if ( ref($replacement) eq 'CODE' ) { |
57
|
20
|
|
|
|
|
165
|
$v =~ s/$regexp/$replacement->()/e; |
|
20
|
|
|
|
|
63
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
40
|
100
|
|
|
|
140
|
Mouse::Util::TypeConstraints::Str($replacement) |
61
|
|
|
|
|
|
|
or $self->meta->throw_error( |
62
|
|
|
|
|
|
|
"The second argument passed to replace must be a string" |
63
|
|
|
|
|
|
|
. " or code reference"); |
64
|
30
|
|
|
|
|
332
|
$v =~ s/$regexp/$replacement/; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
50
|
|
|
|
|
338
|
$writer->( $instance, $v ); |
68
|
10
|
|
|
|
|
68
|
}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub generate_replace_globally { |
72
|
0
|
|
|
90
|
1
|
0
|
my($self) = @_; |
73
|
0
|
|
|
|
|
0
|
my $reader = $self->reader; |
74
|
0
|
|
|
|
|
0
|
my $writer = $self->writer; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return sub { |
77
|
0
|
|
|
90
|
|
0
|
my( $instance, $regexp, $replacement ) = @_; |
78
|
0
|
0
|
|
|
|
0
|
if(@_ != 3) { |
79
|
0
|
|
|
|
|
0
|
$self->argument_error('replace_globally', 3, 3, scalar @_); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
0
|
|
|
0
|
( Mouse::Util::TypeConstraints::Str($regexp) |
82
|
|
|
|
|
|
|
|| Mouse::Util::TypeConstraints::RegexpRef($regexp) ) |
83
|
|
|
|
|
|
|
or $self->meta->throw_error( |
84
|
|
|
|
|
|
|
"The first argument passed to replace_globally must be a string" |
85
|
|
|
|
|
|
|
. " or regexp reference"); |
86
|
0
|
|
|
|
|
0
|
my $v = $reader->( $instance ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
if ( ref($replacement) eq 'CODE' ) { |
89
|
0
|
|
|
|
|
0
|
$v =~ s/$regexp/$replacement->()/eg; |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
0
|
0
|
|
|
|
0
|
Mouse::Util::TypeConstraints::Str($replacement) |
93
|
|
|
|
|
|
|
or $self->meta->throw_error( |
94
|
|
|
|
|
|
|
"The second argument passed to replace must be a string" |
95
|
|
|
|
|
|
|
. " or code reference"); |
96
|
0
|
|
|
|
|
0
|
$v =~ s/$regexp/$replacement/g; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
$writer->( $instance, $v ); |
100
|
0
|
|
|
|
|
0
|
}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub generate_match { |
104
|
10
|
|
|
100
|
1
|
174
|
my($self) = @_; |
105
|
10
|
|
|
|
|
31
|
my $reader = $self->reader; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return sub { |
108
|
80
|
|
|
150
|
|
19394
|
my($instance, $regexp) = @_; |
109
|
80
|
100
|
|
|
|
237
|
if(@_ != 2) { |
110
|
10
|
|
|
|
|
59
|
$self->argument_error('match', 2, 2, scalar @_); |
111
|
|
|
|
|
|
|
} |
112
|
70
|
100
|
100
|
|
|
470
|
( Mouse::Util::TypeConstraints::Str($regexp) |
113
|
|
|
|
|
|
|
|| Mouse::Util::TypeConstraints::RegexpRef($regexp) ) |
114
|
|
|
|
|
|
|
or $self->meta->throw_error( |
115
|
|
|
|
|
|
|
"The argument passed to match must be a string" |
116
|
|
|
|
|
|
|
. " or regexp reference"); |
117
|
60
|
|
|
|
|
912
|
$reader->( $instance ) =~ $regexp; |
118
|
10
|
|
|
|
|
103
|
}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub generate_chop { |
122
|
5
|
|
|
155
|
1
|
8609
|
my($self) = @_; |
123
|
5
|
|
|
|
|
21
|
my $reader = $self->reader; |
124
|
5
|
|
|
|
|
19
|
my $writer = $self->writer; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return sub { |
127
|
20
|
|
|
100
|
|
13086
|
my($instance) = @_; |
128
|
20
|
100
|
|
|
|
68
|
if(@_ != 1) { |
129
|
10
|
|
|
|
|
45
|
$self->argument_error('chop', 1, 1, scalar @_); |
130
|
|
|
|
|
|
|
} |
131
|
10
|
|
|
|
|
39
|
my $v = $reader->( $instance ); |
132
|
10
|
|
|
|
|
24
|
my $r = chop($v); |
133
|
10
|
|
|
|
|
51
|
$writer->( $instance, $v ); |
134
|
10
|
|
|
|
|
80
|
return $r; |
135
|
5
|
|
|
|
|
47
|
}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub generate_chomp { |
139
|
5
|
|
|
105
|
1
|
97
|
my($self) = @_; |
140
|
5
|
|
|
|
|
18
|
my $reader = $self->reader; |
141
|
5
|
|
|
|
|
13
|
my $writer = $self->writer; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
return sub { |
144
|
30
|
|
|
130
|
|
14240
|
my($instance) = @_; |
145
|
30
|
100
|
|
|
|
98
|
if(@_ != 1) { |
146
|
10
|
|
|
|
|
55
|
$self->argument_error('chomp', 1, 1, scalar @_); |
147
|
|
|
|
|
|
|
} |
148
|
20
|
|
|
|
|
61
|
my $v = $reader->( $instance ); |
149
|
20
|
|
|
|
|
55
|
my $r = chomp($v); |
150
|
20
|
|
|
|
|
79
|
$writer->( $instance, $v ); |
151
|
20
|
|
|
|
|
137
|
return $r; |
152
|
5
|
|
|
|
|
32
|
}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub generate_inc { |
156
|
5
|
|
|
135
|
1
|
90
|
my($self) = @_; |
157
|
5
|
|
|
|
|
16
|
my $reader = $self->reader; |
158
|
5
|
|
|
|
|
12
|
my $writer = $self->writer; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
return sub { |
161
|
20
|
|
|
70
|
|
13471
|
my($instance) = @_; |
162
|
20
|
100
|
|
|
|
74
|
if(@_ != 1) { |
163
|
10
|
|
|
|
|
47
|
$self->argument_error('inc', 1, 1, scalar @_); |
164
|
|
|
|
|
|
|
} |
165
|
10
|
|
|
|
|
39
|
my $v = $reader->( $instance ); |
166
|
10
|
|
|
|
|
45
|
$v++; |
167
|
10
|
|
|
|
|
65
|
$writer->( $instance, $v ); |
168
|
5
|
|
|
|
|
33
|
}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub generate_clear { |
172
|
5
|
|
|
75
|
1
|
92
|
my($self) = @_; |
173
|
5
|
|
|
|
|
17
|
my $writer = $self->writer; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return sub { |
176
|
20
|
|
|
70
|
|
496
|
my($instance) = @_; |
177
|
20
|
100
|
|
|
|
67
|
if(@_ != 1) { |
178
|
10
|
|
|
|
|
72
|
$self->argument_error('clear', 1, 1, scalar @_); |
179
|
|
|
|
|
|
|
} |
180
|
10
|
|
|
|
|
86
|
$writer->( $instance, '' ); |
181
|
5
|
|
|
|
|
68
|
}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub generate_length { |
185
|
5
|
|
|
75
|
1
|
89
|
my($self) = @_; |
186
|
5
|
|
|
|
|
14
|
my $reader = $self->reader; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
return sub { |
189
|
30
|
100
|
|
70
|
|
48730
|
if(@_ != 1) { |
190
|
10
|
|
|
|
|
67
|
$self->argument_error('length', 1, 1, scalar @_); |
191
|
|
|
|
|
|
|
} |
192
|
20
|
|
|
|
|
127
|
return length( $reader->($_[0]) ); |
193
|
5
|
|
|
|
|
28
|
}; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub generate_substr { |
197
|
20
|
|
|
90
|
1
|
323
|
my($self) = @_; |
198
|
20
|
|
|
|
|
65
|
my $reader = $self->reader; |
199
|
20
|
|
|
|
|
179
|
my $writer = $self->writer; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
return sub { |
202
|
150
|
|
|
200
|
|
77904
|
my($instance, $offset, $length, $replacement) = @_; |
203
|
150
|
100
|
100
|
|
|
856
|
if(@_ < 2 or @_ > 4) { |
204
|
20
|
|
|
|
|
101
|
$self->argument_error('substr', 2, 4, scalar @_); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
130
|
|
|
|
|
380
|
my $v = $reader->($instance); |
208
|
|
|
|
|
|
|
|
209
|
130
|
100
|
|
|
|
408
|
Mouse::Util::TypeConstraints::Int($offset) |
210
|
|
|
|
|
|
|
or $self->meta->throw_error( |
211
|
|
|
|
|
|
|
"The first argument passed to substr must be an integer"); |
212
|
|
|
|
|
|
|
|
213
|
120
|
100
|
|
|
|
242
|
if(defined $length) { |
214
|
100
|
100
|
|
|
|
291
|
Mouse::Util::TypeConstraints::Int($length) |
215
|
|
|
|
|
|
|
or $self->meta->throw_error( |
216
|
|
|
|
|
|
|
"The second argument passed to substr must be an integer"); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
else { |
219
|
20
|
|
|
|
|
37
|
$length = length($v); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
110
|
|
|
|
|
128
|
my $ret; |
223
|
110
|
100
|
|
|
|
257
|
if ( defined $replacement ) { |
224
|
60
|
100
|
|
|
|
207
|
Mouse::Util::TypeConstraints::Str($replacement) |
225
|
|
|
|
|
|
|
or $self->meta->throw_error( |
226
|
|
|
|
|
|
|
"The third argument passed to substr must be a string"); |
227
|
50
|
|
|
|
|
124
|
$ret = substr( $v, $offset, $length, $replacement ); |
228
|
50
|
|
|
|
|
207
|
$writer->( $instance, $v ); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
else { |
231
|
50
|
|
|
|
|
115
|
$ret = substr( $v, $offset, $length ); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
100
|
|
|
|
|
540
|
return $ret; |
235
|
20
|
|
|
|
|
229
|
}; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
2
|
|
|
2
|
|
17
|
no Mouse; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
15
|
|
239
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
__END__ |