1Scalar::Properties(3) User Contributed Perl DocumentationScalar::Properties(3)
2
3
4

NAME

6       Scalar::Properties - Run-time properties on scalar variables
7

VERSION

9       version 1.100860
10

SYNOPSIS

12         use Scalar::Properties;
13         my $val = 0->true;
14           if ($val && $val == 0) {
15           print "yup, its true alright...\n";
16         }
17
18         my @text = (
19           'hello world'->greeting(1),
20           'forget it',
21           'hi there'->greeting(1),
22         );
23         print grep { $_->is_greeting } @text;
24
25         my $l =  'hello world'->length;
26

DESCRIPTION

28       Scalar::Properties attempts to make Perl more object-oriented by taking
29       an idea from Ruby: Everything you manipulate is an object, and the
30       results of those manipulations are objects themselves.
31
32         'hello world'->length
33         (-1234)->abs
34         "oh my god, it's full of properties"->index('g')
35
36       The first example asks a string to calculate its length. The second
37       example asks a number to calculate its absolute value. And the third
38       example asks a string to find the index of the letter 'g'.
39
40       Using this module you can have run-time properties on initialized
41       scalar variables and literal values. The word 'properties' is used in
42       the Perl 6 sense: out-of-band data, little sticky notes that are
43       attached to the value. While attributes (as in Perl 5's attribute
44       pragma, and see the "Attribute::*" family of modules) are handled at
45       compile-time, properties are handled at run-time.
46
47       Internally properties are implemented by making their values into
48       objects with overloaded operators. The actual properties are then
49       simply hash entries.
50
51       Most properties are simply notes you attach to the value, but some may
52       have deeper meaning. For example, the "true" and "false" properties
53       plays a role in boolean context, as the first example of the Synopsis
54       shows.
55
56       Properties can also be propagated between values. For details, see the
57       EXPORTS section below. Here is an example why this might be desirable:
58
59         pass_on('approximate');
60         my $pi = 3->approximate(1);
61         my $circ = 2 * $rad * $pi;
62
63         # now $circ->approximate indicates that this value was derived
64         # from approximate values
65
66       Please don't use properties whose name start with an underscore; these
67       are reserved for internal use.
68
69       You can set and query properties like this:
70
71       "$var->myprop(1)"
72           sets the property to a true value.
73
74       "$var->myprop(0)"
75           sets the property to a false value. Note that this doesn't delete
76           the property (to do so, use the "del_props" method described
77           below).
78
79       "$var->is_myprop", "$var->has_myprop"
80           returns a true value if the property is set (i.e., defined and has
81           a true value). The two alternate interfaces are provided to make
82           querying attributes sound more natural. For example:
83
84             $foo->is_approximate;
85             $bar->has_history;
86
87       Values thus made into objects also expose various utility methods.  All
88       of those methods (unless noted otherwise) return the result as an
89       overloaded value ready to take properties and method calls itself, and
90       don't modify the original value.
91

METHODS

93   get_props
94       Get a list of names of the value's properties.
95
96   del_props(LIST)
97       Deletes one or more properties from the value. This is different than
98       setting the property value to zero.
99
100   del_all_props
101       Deletes all of the value's properties.
102
103   plus(EXPR)
104       Returns the value that is the sum of the value whose method has been
105       called and the argument value. This method also overloads addition, so:
106
107         $a = 7 + 2;
108         $a = 7->plus(2);    # the same
109
110   minus(EXPR)
111       Returns the value that is the the value whose method has been called
112       minus the argument value. This method also overloads subtraction.
113
114   times(EXPR)
115       Returns the value that is the the value whose method has been called
116       times the argument value. This method also overloads multiplication.
117
118   divide(EXPR)
119       Returns the value that is the the value whose method has been called
120       divided by the argument value. This method also overloads division.
121
122   modulo(EXPR)
123       Returns the value that is the the value whose method has been called
124       modulo the argument value. This method also overloads the modulo
125       operator.
126
127   exp(EXPR)
128       Returns the value that is the the value whose method has been called
129       powered by the argument value. This method also overloads the
130       exponentiation operator.
131
132   abs
133       Returns the absolute of the value.
134
135   zero
136       Returns a boolean value indicating whether the value is equal to 0.
137
138   length
139       Returns the result of the built-in "length" function applied to the
140       value.
141
142   size
143       Same as length().
144
145   reverse
146       Returns the reverse string of the value.
147
148   uc
149       Returns the result of the built-in function uc() applied to the value.
150
151   ucfirst
152       Returns the result of the built-in function ucfirst() applied to the
153       value.
154
155   lc
156       Returns the result of the built-in function lc() applied to the value.
157
158   lcfirst
159       Returns the result of the built-in function lcfirst() applied to the
160       value.
161
162   hex
163       Returns the result of the built-in function hex() applied to the value.
164
165   oct
166       Returns the result of the built-in function oct() applied to the value.
167
168   concat(EXPR)
169       Returns the result of the argument expression appended to the value.
170
171   append(EXPR)
172       Same as concat(EXPR).
173
174   swapcase
175       Returns a version of the value with every character's case reversed,
176       i.e. a lowercase character becomes uppercase and vice versa.
177
178   split /PATTERN/, LIMIT
179       Returns a list of overloaded values that is the result of splitting
180       (according to the built-in "split" function) the value along the
181       pattern, into a number of values up to the limit.
182
183   numcmp(EXPR)
184       Returns the (overloaded) value of the numerical three-way comparison.
185       This method also overloads the "<=>" operator.
186
187   cmp(EXPR)
188       Returns the (overloaded) value of the alphabetical three-way
189       comparison.  This method also overloads the "cmp" operator.
190
191   eq(EXPR)
192       Return the (overloaded) boolean value of the "eq" string comparison.
193       This method also overloads that operators.
194
195   ne(EXPR)
196       Return the (overloaded) boolean value of the "ne" string comparison.
197       This method also overloads that operators.
198
199   lt(EXPR)
200       Return the (overloaded) boolean value of the "lt" string comparison.
201       This method also overloads that operators.
202
203   gt(EXPR)
204       Return the (overloaded) boolean value of the "gt" string comparison.
205       This method also overloads that operators.
206
207   le(EXPR)
208       Return the (overloaded) boolean value of the "le" string comparison.
209       This method also overloads that operators.
210
211   ge(EXPR)
212       Return the (overloaded) boolean value of the "ge" string comparison.
213       This method also overloads that operators.
214
215   eqi
216       Same as eq(), but is case-insensitive.
217
218   nei>
219       Same as ne(), but is case-insensitive.
220
221   lti
222       Same as lt(), but is case-insensitive.
223
224   gti
225       Same as gt(), but is case-insensitive.
226
227   lei
228       Same as le(), but is case-insensitive.
229
230   gei
231       Same as ge(), but is case-insensitive.
232
233   is_true
234       Returns whether the (overloaded) boolean status of the value is true.
235
236   is_false
237       Returns whether the (overloaded) boolean status of the value is false.
238
239   create
240       FIXME
241
242   del_prop
243       FIXME
244
245   do_downto
246       FIXME
247
248   do_downto_step
249       FIXME
250
251   do_upto
252       FIXME
253
254   do_upto_step
255       FIXME
256
257   false
258       FIXME
259
260   gen_meth
261       FIXME
262
263   handle
264       FIXME
265
266   times_do
267       FIXME
268
269   true
270       FIXME
271
272   value
273       FIXME
274

FUNCTIONS

276   pass_on(LIST)
277       Sets (replaces) the list of properties that are passed on. There is
278       only one such list for the whole mechanism. The whole property
279       interface is experimental, but this one in particular is likely to
280       change in the future. This function is exported automatically.
281
282   passed_on(STRING)
283       Tests whether a property is passed on and returns a boolean value. This
284       function is exported automatically.
285
286   get_pass_on
287       Returns a list of names of properties that are passed on. This function
288       is exported automatically.
289

INSTALLATION

291       See perlmodinstall for information and options on installing Perl
292       modules.
293

BUGS AND LIMITATIONS

295       No bugs have been reported.
296
297       Please report any bugs or feature requests through the web interface at
298       <http://rt.cpan.org/Public/Dist/Display.html?Name=Scalar-Properties>.
299

AVAILABILITY

301       The latest version of this module is available from the Comprehensive
302       Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find
303       a CPAN site near you, or see
304       <http://search.cpan.org/dist/Scalar-Properties/>.
305
306       The development version lives at
307       <http://github.com/hanekomu/Scalar-Properties/>.  Instead of sending
308       patches, please fork this project using the standard git and github
309       infrastructure.
310

AUTHOR

312         Marcel Gruenauer <marcel@cpan.org>
313
315       This software is copyright (c) 2001 by Marcel Gruenauer.
316
317       This is free software; you can redistribute it and/or modify it under
318       the same terms as the Perl 5 programming language system itself.
319
320
321
322perl v5.36.0                      2023-01-20             Scalar::Properties(3)
Impressum