… | |
… | |
14 | different implementations so they become interoperable between each other. |
14 | different implementations so they become interoperable between each other. |
15 | |
15 | |
16 | =cut |
16 | =cut |
17 | |
17 | |
18 | package Types::Serialiser; |
18 | package Types::Serialiser; |
19 | |
|
|
20 | use common::sense; |
|
|
21 | |
19 | |
22 | our $VERSION = 0.01; |
20 | our $VERSION = 0.01; |
23 | |
21 | |
24 | =head1 SIMPLE SCALAR CONSTANTS |
22 | =head1 SIMPLE SCALAR CONSTANTS |
25 | |
23 | |
… | |
… | |
122 | |
120 | |
123 | package Types::Serialiser::Error; |
121 | package Types::Serialiser::Error; |
124 | |
122 | |
125 | sub error { |
123 | sub error { |
126 | require Carp; |
124 | require Carp; |
127 | Carp::croak ("caught attempt to use Types::Serialiser::error value"); |
125 | Carp::croak ("caught attempt to use the Types::Serialiser::error value"); |
128 | }; |
126 | }; |
129 | |
127 | |
130 | use overload |
128 | use overload |
131 | "0+" => \&error, |
129 | "0+" => \&error, |
132 | "++" => \&error, |
130 | "++" => \&error, |
133 | "--" => \&error, |
131 | "--" => \&error, |
134 | fallback => 1; |
132 | fallback => 1; |
|
|
133 | |
|
|
134 | =head1 NOTES FOR XS USERS |
|
|
135 | |
|
|
136 | The recommended way to detect whether a scalar is one of these objects |
|
|
137 | is to check whether the stash is the C<Types::Serialiser::Boolean> or |
|
|
138 | C<Types::Serialiser::Error> stash, and then follow the scalar reference to |
|
|
139 | see if it's C<1> (true), C<0> (false) or C<undef> (error). |
|
|
140 | |
|
|
141 | While it is possible to use an isa test, directly comparing stash pointers |
|
|
142 | is faster and guaranteed to work. |
135 | |
143 | |
136 | =head1 BUGS |
144 | =head1 BUGS |
137 | |
145 | |
138 | The use of L<overload> makes this module much heavier than it should be |
146 | The use of L<overload> makes this module much heavier than it should be |
139 | (on my system, this module: 4kB RSS, overload: 260kB RSS). |
147 | (on my system, this module: 4kB RSS, overload: 260kB RSS). |