root/docs/Perl6/API/Scalar.pod

Revision 17701, 2.4 kB (checked in by lwall, 15 months ago)

s:g/err/orelse/

Line 
1
2=encoding utf8
3
4=head1 Title
5
6Scalar API reference
7
8=head2 Typical usage
9
10use Scalar
11
12=head2 Exported functions
13
14The following functions are exported by default:
15
16=over
17
18=item defined
19
20  our Bool multi Scalar::defined ( Any $thing )
21  our Bool multi Scalar::defined ( Any $thing, ::role )
22
23C<defined> returns true if the parameter has a value and that value is
24not the undefined value (per C<undef>), otherwise false is returned.
25
26Same as Perl 5, only takes extra optional argument to ask if value is defined
27with respect to a particular role:
28
29    $x.defined(SomeRole);
30
31A value may be defined according to one role and undefined according to another.
32Without the extra argument, defaults to the definition of defined supplied by
33the type of the object.
34
35=item undefine
36
37  our multi Any::undefine( Any $thing )
38
39Takes any variable as a parameter and attempts to "remove" its
40definition. For simple scalar variables this means assigning
41the undefined value to the variable. For objects, this is equivalent
42to invoking their undefine method. For arrays, hashes and other
43complex data, this might require emptying the structures associated
44with the object.
45
46In all cases, calling C<undefine> on a variable
47should place the object in the same state as if it was just
48declared.
49
50=item undef
51
52  constant Scalar Scalar::undef
53
54Returns the undefined scalar object. C<undef> has no value at
55all, but for historical compatibility, it will numify to C<0>
56and stringify to the empty string, potentially generating a
57warning in doing so. There are two ways to determine if a
58value equal to undef: the C<defined> function (or method) can
59be called or the C<//> (or C<orelse>) operator can be used.
60
61C<undef> is also considered to be false in a boolean context.
62Such a conversion does not generate a warning.
63
64Perl 5's unary C<undef> function is renamed C<undefine> to avoid
65confusion with the value C<undef> (which is always 0-ary now).
66
67=back
68
69=head2 Methods
70
71These functions are also provided as methods, which can be called an
72any scalar type:
73
74=over
75
76=item defined
77
78  our Bool multi method Scalar::defined ( Scalar $thing: )
79  our Bool multi method Scalar::defined ( Scalar $thing: ::role )
80
81Returns a true value if C<$thing> is defined. See above for the meaning
82of the C<::role> argument.
83
84=item undefine
85
86  our multi method Any::undefine ( Any $thing: )
87
88Sets the invocant (C<$thing>) to an undefined value.
89
90=cut
Note: See TracBrowser for help on using the browser.