ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-Scalar/Scalar.pm
(Generate patch)

Comparing Convert-Scalar/Scalar.pm (file contents):
Revision 1.6 by root, Sat Apr 24 06:23:12 2004 UTC vs.
Revision 1.15 by root, Mon Feb 3 03:32:13 2014 UTC

24=cut 24=cut
25 25
26package Convert::Scalar; 26package Convert::Scalar;
27 27
28BEGIN { 28BEGIN {
29 $VERSION = '1.0'; 29 $VERSION = '1.1';
30 @ISA = qw(Exporter); 30 @ISA = qw(Exporter);
31 @EXPORT_OK = qw(weaken unmagic grow); 31 @EXPORT_OK = qw(readonly readonly_on readonly_off weaken unmagic len grow extend);
32 %EXPORT_TAGS = ( 32 %EXPORT_TAGS = (
33 taint => [qw(taint untaint tainted)], 33 taint => [qw(taint untaint tainted)],
34 utf8 => [qw(utf8 utf8_on utf8_off utf8_valid utf8_upgrade utf8_downgrade utf8_encode utf8_decode utf8_length)], 34 utf8 => [qw(utf8 utf8_on utf8_off utf8_valid utf8_upgrade utf8_downgrade utf8_encode utf8_decode utf8_length)],
35 refcnt => [qw(refcnt refcnt_inc refcnt_dec refcnt_rv refcnt_inc_rv refcnt_dec_rv)], 35 refcnt => [qw(refcnt refcnt_inc refcnt_dec refcnt_rv refcnt_inc_rv refcnt_dec_rv)],
36 ok => [qw(ok uok rok pok nok niok)], 36 ok => [qw(ok uok rok pok nok niok)],
94 94
95Returns the number of characters in the string, counting wide UTF8 95Returns the number of characters in the string, counting wide UTF8
96characters as a single character, independent of wether the scalar is 96characters as a single character, independent of wether the scalar is
97marked as containing bytes or mulitbyte characters. 97marked as containing bytes or mulitbyte characters.
98 98
99=item $old = readonly scalar[, $new]
100
101Returns whether the scalar is currently readonly, and sets or clears the
102readonly status if a new status is given.
103
104=item readonly_on scalar
105
106Sets the readonly flag on the scalar.
107
108=item readonly_off scalar
109
110Clears the readonly flag on the scalar.
111
99=item unmagic scalar 112=item unmagic scalar, type
100 113
101Removes magic from the scalar. 114Remove the specified magic from the scalar (DANGEROUS!).
102 115
103=item weaken scalar 116=item weaken scalar
104 117
105Weaken a reference. (See also L<WeakRef>). 118Weaken a reference. (See also L<WeakRef>).
106 119
110 123
111=item tainted scalar 124=item tainted scalar
112 125
113returns true when the scalar is tainted, false otherwise. 126returns true when the scalar is tainted, false otherwise.
114 127
115=item untaint scalar, type 128=item untaint scalar
116 129
117Remove the specified magic from the scalar 130Remove the tainted flag from the specified scalar.
118(DANGEROUS!), L<perlguts>. L<Untaint>, for a similar but different
119interface.
120 131
132=item length = len scalar
133
134Returns SvLEN (scalar), that is, the actual number of bytes allocated to
135the string value, or C<undef>, is the scalar has no string value.
136
121=item grow scalar, newlen 137=item scalar = grow scalar, newlen
122 138
123Sets the memory area used for the scalar to the given length, if the 139Sets the memory area used for the scalar to the given length, if the
124current length is less than the new value. This does not affect the 140current length is less than the new value. This does not affect the
125contents of the scalar, but is only useful to "pre-allocate" memory space 141contents of the scalar, but is only useful to "pre-allocate" memory space
126if you know the scalar will grow. The return value is the modified scalar 142if you know the scalar will grow. The return value is the modified scalar
127(the scalar is modified in-place). 143(the scalar is modified in-place).
128 144
145=item scalar = extend scalar, addlen
146
147Reserves enough space in the scalar so that addlen bytes can be appended
148without reallocating it. The actual contents of the scalar will not be
149affected. The modified scalar will also be returned.
150
151This function is meant to make append workloads efficient - if you append
152a short string to a scalar many times (millions of times), then perl will
153have to reallocate and copy the scalar basically every time.
154
155If you instead use C<extend $scalar, length $shortstring>, then
156Convert::Scalar will use a "size to next power of two, roughly" algorithm,
157so as the scalar grows, perl will have to resize and copy it less and less
158often.
159
129=item refcnt scalar[, newrefcnt] 160=item refcnt scalar[, newrefcnt]
130 161
131Returns the current reference count of the given scalar and optionally sets it to 162Returns the current reference count of the given scalar and optionally sets it to
132the given reference count. 163the given reference count.
133 164
170=item niok scalar 201=item niok scalar
171 202
172Calls SvOK, SvUOK, SvROK, SvPOK, SvNOK or SvNIOK on the given scalar, 203Calls SvOK, SvUOK, SvROK, SvPOK, SvNOK or SvNIOK on the given scalar,
173respectively. 204respectively.
174 205
175=cut
176
1771;
178
179=back 206=back
180 207
181=head2 CANDIDATES FOR FUTURE RELEASES 208=head2 CANDIDATES FOR FUTURE RELEASES
182 209
183The following API functions (L<perlapi>) are considered for future 210The following API functions (L<perlapi>) are considered for future
188 sv_pvutf8n_force 215 sv_pvutf8n_force
189 the sv2xx family 216 the sv2xx family
190 217
191=head1 AUTHOR 218=head1 AUTHOR
192 219
193 Marc Lehmann <pcg@goof.com> 220 Marc Lehmann <schmorp@schmorp.de>
194 http://www.goof.com/pcg/marc/ 221 http://home.schmorp.de/
195 222
196=cut 223=cut
197 224
2251
226

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines