… | |
… | |
24 | =cut |
24 | =cut |
25 | |
25 | |
26 | package Convert::Scalar; |
26 | package Convert::Scalar; |
27 | |
27 | |
28 | BEGIN { |
28 | BEGIN { |
29 | $VERSION = 0.1; |
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 | |
95 | Returns the number of characters in the string, counting wide UTF8 |
95 | Returns the number of characters in the string, counting wide UTF8 |
96 | characters as a single character, independent of wether the scalar is |
96 | characters as a single character, independent of wether the scalar is |
97 | marked as containing bytes or mulitbyte characters. |
97 | marked as containing bytes or mulitbyte characters. |
98 | |
98 | |
|
|
99 | =item $old = readonly scalar[, $new] |
|
|
100 | |
|
|
101 | Returns whether the scalar is currently readonly, and sets or clears the |
|
|
102 | readonly status if a new status is given. |
|
|
103 | |
|
|
104 | =item readonly_on scalar |
|
|
105 | |
|
|
106 | Sets the readonly flag on the scalar. |
|
|
107 | |
|
|
108 | =item readonly_off scalar |
|
|
109 | |
|
|
110 | Clears the readonly flag on the scalar. |
|
|
111 | |
99 | =item unmagic scalar |
112 | =item unmagic scalar, type |
100 | |
113 | |
101 | Removes magic from the scalar. |
114 | Remove the specified magic from the scalar (DANGEROUS!). |
102 | |
115 | |
103 | =item weaken scalar |
116 | =item weaken scalar |
104 | |
117 | |
105 | Weaken a reference. (See also L<WeakRef>). |
118 | Weaken a reference. (See also L<WeakRef>). |
106 | |
119 | |
… | |
… | |
110 | |
123 | |
111 | =item tainted scalar |
124 | =item tainted scalar |
112 | |
125 | |
113 | returns true when the scalar is tainted, false otherwise. |
126 | returns true when the scalar is tainted, false otherwise. |
114 | |
127 | |
115 | =item untaint scalar, type |
128 | =item untaint scalar |
116 | |
129 | |
117 | Remove the specified magic from the scalar |
130 | Remove the tainted flag from the specified scalar. |
118 | (DANGEROUS!), L<perlguts>. L<Untaint>, for a similar but different |
|
|
119 | interface. |
|
|
120 | |
131 | |
|
|
132 | =item length = len scalar |
|
|
133 | |
|
|
134 | Returns SvLEN (scalar), that is, the actual number of bytes allocated to |
|
|
135 | the 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 | |
123 | Sets the memory area used for the scalar to the given length, if the |
139 | Sets the memory area used for the scalar to the given length, if the |
124 | current length is less than the new value. This does not affect the |
140 | current length is less than the new value. This does not affect the |
125 | contents of the scalar, but is only useful to "pre-allocate" memory space |
141 | contents of the scalar, but is only useful to "pre-allocate" memory space |
126 | if you know the scalar will grow. The return value is the modified scalar |
142 | if 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 | |
|
|
147 | Reserves enough space in the scalar so that addlen bytes can be appended |
|
|
148 | without reallocating it. The actual contents of the scalar will not be |
|
|
149 | affected. The modified scalar will also be returned. |
|
|
150 | |
|
|
151 | This function is meant to make append workloads efficient - if you append |
|
|
152 | a short string to a scalar many times (millions of times), then perl will |
|
|
153 | have to reallocate and copy the scalar basically every time. |
|
|
154 | |
|
|
155 | If you instead use C<extend $scalar, length $shortstring>, then |
|
|
156 | Convert::Scalar will use a "size to next power of two, roughly" algorithm, |
|
|
157 | so as the scalar grows, perl will have to resize and copy it less and less |
|
|
158 | often. |
|
|
159 | |
129 | =item refcnt scalar[, newrefcnt] |
160 | =item refcnt scalar[, newrefcnt] |
130 | |
161 | |
131 | Returns the current reference count of the given scalar and optionally sets it to |
162 | Returns the current reference count of the given scalar and optionally sets it to |
132 | the given reference count. |
163 | the given reference count. |
133 | |
164 | |
… | |
… | |
141 | instead if you understand what this function is fore. Better yet: don't |
172 | instead if you understand what this function is fore. Better yet: don't |
142 | use this module in this case. |
173 | use this module in this case. |
143 | |
174 | |
144 | =item refcnt_rv scalar[, newrefcnt] |
175 | =item refcnt_rv scalar[, newrefcnt] |
145 | |
176 | |
146 | Works like C<refcnt>, but dereferences the given reference first. Remember |
177 | Works like C<refcnt>, but dereferences the given reference first. This is |
147 | that taking a reference of some object increases it's reference count, so |
178 | useful to find the reference count of arrays or hashes, which cnanot be |
148 | the reference count used by the C<*_rv>-funtions tend to be one higher. |
179 | passed directly. Remember that taking a reference of some object increases |
|
|
180 | it's reference count, so the reference count used by the C<*_rv>-functions |
|
|
181 | tend to be one higher. |
149 | |
182 | |
150 | =item refcnt_inc_rv scalar |
183 | =item refcnt_inc_rv scalar |
151 | |
184 | |
152 | Works like C<refcnt_inc>, but dereferences the given reference first. |
185 | Works like C<refcnt_inc>, but dereferences the given reference first. |
153 | |
186 | |
… | |
… | |
186 | sv_pvutf8n_force |
219 | sv_pvutf8n_force |
187 | the sv2xx family |
220 | the sv2xx family |
188 | |
221 | |
189 | =head1 AUTHOR |
222 | =head1 AUTHOR |
190 | |
223 | |
191 | Marc Lehmann <pcg@goof.com> |
224 | Marc Lehmann <schmorp@schmorp.de> |
192 | http://www.goof.com/pcg/marc/ |
225 | http://home.schmorp.de/ |
193 | |
226 | |
194 | =cut |
227 | =cut |
195 | |
228 | |