1 |
=head1 NAME |
2 |
|
3 |
Convert::Scalar - convert between different representations of perl scalars |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
use Convert::Scalar; |
8 |
|
9 |
=head1 DESCRIPTION |
10 |
|
11 |
This module exports various internal perl methods that change the internal |
12 |
representation or state of a perl scalar. All of these work in-place, that |
13 |
is, they modify their scalar argument. No functions are exported by default. |
14 |
|
15 |
The following export tags exist: |
16 |
|
17 |
:utf8 all functions with utf8 in their name |
18 |
:taint all functions with taint in their name |
19 |
:refcnt all functions with refcnt in their name |
20 |
:ok all *ok-functions. |
21 |
|
22 |
=over 4 |
23 |
|
24 |
=cut |
25 |
|
26 |
package Convert::Scalar; |
27 |
|
28 |
BEGIN { |
29 |
$VERSION = 0.1; |
30 |
@ISA = qw(Exporter); |
31 |
@EXPORT_OK = qw(weaken unmagic grow); |
32 |
%EXPORT_TAGS = ( |
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)], |
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)], |
37 |
); |
38 |
|
39 |
require Exporter; |
40 |
Exporter::export_ok_tags(keys %EXPORT_TAGS); |
41 |
|
42 |
require XSLoader; |
43 |
XSLoader::load Convert::Scalar, $VERSION; |
44 |
} |
45 |
|
46 |
=item utf8 scalar[, mode] |
47 |
|
48 |
Returns true when the given scalar is marked as utf8, false otherwise. If |
49 |
the optional mode argument is given, also forces the interpretation of the |
50 |
string to utf8 (mode true) or plain bytes (mode false). The actual (byte-) |
51 |
content is not changed. The return value always reflects the state before |
52 |
any modification is done. |
53 |
|
54 |
This function is useful when you "import" utf8-data into perl, or when |
55 |
some external function (e.g. storing/retrieving from a database) removes |
56 |
the utf8-flag. |
57 |
|
58 |
=item utf8_on scalar |
59 |
|
60 |
Similar to C<utf8 scalar, 1>, but additionally returns the scalar (the |
61 |
argument is still modified in-place). |
62 |
|
63 |
=item utf8_off scalar |
64 |
|
65 |
Similar to C<utf8 scalar, 0>, but additionally returns the scalar (the |
66 |
argument is still modified in-place). |
67 |
|
68 |
=item utf8_valid scalar [Perl 5.7] |
69 |
|
70 |
Returns true if the bytes inside the scalar form a valid utf8 string, |
71 |
false otherwise (the check is independent of the actual encoding perl |
72 |
thinks the string is in). |
73 |
|
74 |
=item utf8_upgrade scalar |
75 |
|
76 |
Convert the string content of the scalar in-place to its UTF8-encoded form |
77 |
(and also returns it). |
78 |
|
79 |
=item utf8_downgrade scalar[, fail_ok=0] |
80 |
|
81 |
Attempt to convert the string content of the scalar from UTF8-encoded to |
82 |
ISO-8859-1. This may not be possible if the string contains characters |
83 |
that cannot be represented in a single byte; if this is the case, it |
84 |
leaves the scalar unchanged and either returns false or, if C<fail_ok> is |
85 |
not true (the default), croaks. |
86 |
|
87 |
=item utf8_encode scalar |
88 |
|
89 |
Convert the string value of the scalar to UTF8-encoded, but then turn off |
90 |
the C<SvUTF8> flag so that it looks like bytes to perl again. (Might be |
91 |
removed in future versions). |
92 |
|
93 |
=item utf8_length scalar |
94 |
|
95 |
Returns the number of characters in the string, counting wide UTF8 |
96 |
characters as a single character, independent of wether the scalar is |
97 |
marked as containing bytes or mulitbyte characters. |
98 |
|
99 |
=item unmagic scalar |
100 |
|
101 |
Removes magic from the scalar. |
102 |
|
103 |
=item weaken scalar |
104 |
|
105 |
Weaken a reference. (See also L<WeakRef>). |
106 |
|
107 |
=item taint scalar |
108 |
|
109 |
Taint the scalar. |
110 |
|
111 |
=item tainted scalar |
112 |
|
113 |
returns true when the scalar is tainted, false otherwise. |
114 |
|
115 |
=item untaint scalar, type |
116 |
|
117 |
Remove the specified magic from the scalar |
118 |
(DANGEROUS!), L<perlguts>. L<Untaint>, for a similar but different |
119 |
interface. |
120 |
|
121 |
=item grow scalar, newlen |
122 |
|
123 |
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 |
125 |
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 |
127 |
(the scalar is modified in-place). |
128 |
|
129 |
=item refcnt scalar[, newrefcnt] |
130 |
|
131 |
Returns the current reference count of the given scalar and optionally sets it to |
132 |
the given reference count. |
133 |
|
134 |
=item refcnt_inc scalar |
135 |
|
136 |
Increments the reference count of the given scalar inplace. |
137 |
|
138 |
=item refcnt_dec scalar |
139 |
|
140 |
Decrements the reference count of the given scalar inplace. Use C<weaken> |
141 |
instead if you understand what this function is fore. Better yet: don't |
142 |
use this module in this case. |
143 |
|
144 |
=item refcnt_rv scalar[, newrefcnt] |
145 |
|
146 |
Works like C<refcnt>, but dereferences the given reference first. Remember |
147 |
that taking a reference of some object increases it's reference count, so |
148 |
the reference count used by the C<*_rv>-funtions tend to be one higher. |
149 |
|
150 |
=item refcnt_inc_rv scalar |
151 |
|
152 |
Works like C<refcnt_inc>, but dereferences the given reference first. |
153 |
|
154 |
=item refcnt_dec_rv scalar |
155 |
|
156 |
Works like C<refcnt_dec>, but dereferences the given reference first. |
157 |
|
158 |
=item ok scalar |
159 |
|
160 |
=item uok scalar |
161 |
|
162 |
=item rok scalar |
163 |
|
164 |
=item pok scalar |
165 |
|
166 |
=item nok scalar |
167 |
|
168 |
=item niok scalar |
169 |
|
170 |
Calls SvOK, SvUOK, SvROK, SvPOK, SvNOK or SvNIOK on the given scalar, |
171 |
respectively. |
172 |
|
173 |
=cut |
174 |
|
175 |
1; |
176 |
|
177 |
=back |
178 |
|
179 |
=head2 CANDIDATES FOR FUTURE RELEASES |
180 |
|
181 |
The following API functions (L<perlapi>) are considered for future |
182 |
inclusion in this module If you want them, write me. |
183 |
|
184 |
sv_upgrade |
185 |
sv_pvn_force |
186 |
sv_pvutf8n_force |
187 |
the sv2xx family |
188 |
|
189 |
=head1 AUTHOR |
190 |
|
191 |
Marc Lehmann <pcg@goof.com> |
192 |
http://www.goof.com/pcg/marc/ |
193 |
|
194 |
=cut |
195 |
|