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
150       value.
151
152   ucfirst
153       Returns the result of the built-in function "ucfirst()" applied to the
154       value.
155
156   lc
157       Returns the result of the built-in function "lc()" applied to the
158       value.
159
160   lcfirst
161       Returns the result of the built-in function "lcfirst()" applied to the
162       value.
163
164   hex
165       Returns the result of the built-in function "hex()" applied to the
166       value.
167
168   oct
169       Returns the result of the built-in function "oct()" applied to the
170       value.
171
172   concat(EXPR)
173       Returns the result of the argument expression appended to the value.
174
175   append(EXPR)
176       Same as "concat(EXPR)".
177
178   swapcase
179       Returns a version of the value with every character's case reversed,
180       i.e. a lowercase character becomes uppercase and vice versa.
181
182   split /PATTERN/, LIMIT
183       Returns a list of overloaded values that is the result of splitting
184       (according to the built-in "split" function) the value along the
185       pattern, into a number of values up to the limit.
186
187   numcmp(EXPR)
188       Returns the (overloaded) value of the numerical three-way comparison.
189       This method also overloads the "<=>" operator.
190
191   cmp(EXPR)
192       Returns the (overloaded) value of the alphabetical three-way
193       comparison.  This method also overloads the "cmp" operator.
194
195   eq(EXPR)
196       Return the (overloaded) boolean value of the "eq" string comparison.
197       This method also overloads that operators.
198
199   ne(EXPR)
200       Return the (overloaded) boolean value of the "ne" string comparison.
201       This method also overloads that operators.
202
203   lt(EXPR)
204       Return the (overloaded) boolean value of the "lt" string comparison.
205       This method also overloads that operators.
206
207   gt(EXPR)
208       Return the (overloaded) boolean value of the "gt" string comparison.
209       This method also overloads that operators.
210
211   le(EXPR)
212       Return the (overloaded) boolean value of the "le" string comparison.
213       This method also overloads that operators.
214
215   ge(EXPR)
216       Return the (overloaded) boolean value of the "ge" string comparison.
217       This method also overloads that operators.
218
219   eqi
220       Same as "eq()", but is case-insensitive.
221
222   nei>
223       Same as "ne()", but is case-insensitive.
224
225   lti
226       Same as "lt()", but is case-insensitive.
227
228   gti
229       Same as "gt()", but is case-insensitive.
230
231   lei
232       Same as "le()", but is case-insensitive.
233
234   gei
235       Same as "ge()", but is case-insensitive.
236
237   is_true
238       Returns whether the (overloaded) boolean status of the value is true.
239
240   is_false
241       Returns whether the (overloaded) boolean status of the value is false.
242
243   create
244       FIXME
245
246   del_prop
247       FIXME
248
249   do_downto
250       FIXME
251
252   do_downto_step
253       FIXME
254
255   do_upto
256       FIXME
257
258   do_upto_step
259       FIXME
260
261   false
262       FIXME
263
264   gen_meth
265       FIXME
266
267   handle
268       FIXME
269
270   times_do
271       FIXME
272
273   true
274       FIXME
275
276   value
277       FIXME
278

FUNCTIONS

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

INSTALLATION

295       See perlmodinstall for information and options on installing Perl
296       modules.
297

BUGS AND LIMITATIONS

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

AVAILABILITY

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

AUTHOR

316         Marcel Gruenauer <marcel@cpan.org>
317
319       This software is copyright (c) 2001 by Marcel Gruenauer.
320
321       This is free software; you can redistribute it and/or modify it under
322       the same terms as the Perl 5 programming language system itself.
323
324
325
326perl v5.32.0                      2020-07-28             Scalar::Properties(3)
Impressum