… | |
… | |
12 | SIMPLE SCALAR CONSTANTS |
12 | SIMPLE SCALAR CONSTANTS |
13 | Simple scalar constants are values that are overloaded to act like |
13 | Simple scalar constants are values that are overloaded to act like |
14 | simple Perl values, but have (class) type to differentiate them from |
14 | simple Perl values, but have (class) type to differentiate them from |
15 | normal Perl scalars. This is necessary because these have different |
15 | normal Perl scalars. This is necessary because these have different |
16 | representations in the serialisation formats. |
16 | representations in the serialisation formats. |
|
|
17 | |
|
|
18 | In the following, functions with zero or one arguments have a prototype |
|
|
19 | of "()" and "($)", respectively, so act as constants and unary |
|
|
20 | operators. |
17 | |
21 | |
18 | BOOLEANS (Types::Serialiser::Boolean class) |
22 | BOOLEANS (Types::Serialiser::Boolean class) |
19 | This type has only two instances, true and false. A natural |
23 | This type has only two instances, true and false. A natural |
20 | representation for these in Perl is 1 and 0, but serialisation formats |
24 | representation for these in Perl is 1 and 0, but serialisation formats |
21 | need to be able to differentiate between them and mere numbers. |
25 | need to be able to differentiate between them and mere numbers. |
… | |
… | |
35 | ($Types::Serialiser::false) or the constant form |
39 | ($Types::Serialiser::false) or the constant form |
36 | ("Types::Serialiser::false"). |
40 | ("Types::Serialiser::false"). |
37 | |
41 | |
38 | The constant is represented as a reference to a scalar containing 0 |
42 | The constant is represented as a reference to a scalar containing 0 |
39 | - implementations are allowed to directly test for this. |
43 | - implementations are allowed to directly test for this. |
|
|
44 | |
|
|
45 | Types::Serialiser::as_bool $value |
|
|
46 | Converts a Perl scalar into a boolean, which is useful syntactic |
|
|
47 | sugar. Strictly equivalent to: |
|
|
48 | |
|
|
49 | $value ? $Types::Serialiser::true : $Types::Serialiser::false |
40 | |
50 | |
41 | $is_bool = Types::Serialiser::is_bool $value |
51 | $is_bool = Types::Serialiser::is_bool $value |
42 | Returns true iff the $value is either $Types::Serialiser::true or |
52 | Returns true iff the $value is either $Types::Serialiser::true or |
43 | $Types::Serialiser::false. |
53 | $Types::Serialiser::false. |
44 | |
54 | |