File: README

package info (click to toggle)
libscalar-properties-perl 0.12-1.3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 76 kB
  • ctags: 32
  • sloc: perl: 489; makefile: 43
file content (217 lines) | stat: -rw-r--r-- 7,519 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
NAME
    Scalar::Properties - run-time properties on scalar variables

SYNOPSIS
      use Scalar::Properties;
      my $val = 0->true;
        if ($val && $val == 0) {
        print "yup, its true alright...\n";
      }

      my @text = (
        'hello world'->greeting(1),
        'forget it',
        'hi there'->greeting(1),
      );
      print grep { $_->is_greeting } @text;

      my $l =  'hello world'->length;

DESCRIPTION
    Scalar::Properties attempts to make Perl more object-oriented by taking
    an idea from Ruby: Everything you manipulate is an object, and the
    results of those manipulations are objects themselves.

      'hello world'->length
      -1234->abs
      "oh my god, it's full of properties"->index('g')

    The first example asks a string to calculate its length. The second
    example asks a number to calculate its absolute value. And the third
    example asks a string to find the index of the letter 'g'.

    Using this module you can have run-time properties on initialized scalar
    variables and literal values. The word 'properties' is used in the Perl
    6 sense: out-of-band data, little sticky notes that are attached to the
    value. While attributes (as in Perl 5's attribute pragma, and see the
    `Attribute::*' family of modules) are handled at compile-time,
    properties are handled at run-time.

    Internally properties are implemented by making their values into
    objects with overloaded operators. The actual properties are then simply
    hash entries.

    Most properties are simply notes you attach to the value, but some may
    have deeper meaning. For example, the `true' and `false' properties
    plays a role in boolean context, as the first example of the Synopsis
    shows.

    Properties can also be propagated between values. For details, see the
    EXPORTS section below. Here is an example why this might be desirable:

      pass_on('approximate');
      my $pi = 3->approximate(1);
      my $circ = 2 * $rad * $pi;

      # now $circ->approximate indicates that this value was derived
      # from approximate values

    Please don't use properties whose name start with an underscore; these
    are reserved for internal use.

    You can set and query properties like this:

    `$var->myprop(1)'
        sets the property to a true value.

    `$var->myprop(0)'
        sets the property to a false value. Note that this doesn't delete
        the property (to do so, use the `del_props' method described below).

    `$var->is_myprop', `$var->has_myprop'
        returns a true value if the property is set (i.e., defined and has a
        true value). The two alternate interfaces are provided to make
        querying attributes sound more natural. For example:

          $foo->is_approximate;
          $bar->has_history;

METHODS
    Values thus made into objects also expose various utility methods. All
    of those methods (unless noted otherwise) return the result as an
    overloaded value ready to take properties and method calls itself, and
    don't modify the original value.

  INTROSPECTIVE METHODS

    These methods help in managing a value's properties.

    `$var-'get_props>
        Get a list of names of the value's properties.

    `$var-'del_props(LIST)>
        Deletes one or more properties from the value. This is different
        than setting the property value to zero.

    `$var-'del_all_props>
        Deletes all of the value's properties.

  NUMERICAL METHODS

    `plus(EXPR)'
        Returns the value that is the sum of the value whose method has been
        called and the argument value. This method also overloads addition,
        so:

          $a = 7 + 2;
          $a = 7->plus(2);    # the same

    `minus(EXPR)'
        Returns the value that is the the value whose method has been called
        minus the argument value. This method also overloads subtraction.

    `times(EXPR)'
        Returns the value that is the the value whose method has been called
        times the argument value. This method also overloads multiplication.

    `divide(EXPR)'
        Returns the value that is the the value whose method has been called
        divided by the argument value. This method also overloads division.

    `modulo(EXPR)'
        Returns the value that is the the value whose method has been called
        modulo the argument value. This method also overloads the modulo
        operator.

    `exp(EXPR)'
        Returns the value that is the the value whose method has been called
        powered by the argument value. This method also overloads the
        exponentiation operator.

    `abs'
        Returns the absolute of the value.

    `zero'
        Returns a boolean value indicating whether the value is equal to 0.

  STRING METHODS

    `length', `size'
        Returns the result of the built-in `length' function applied to the
        value.

    `reverse'
        Returns the reverse string of the value.

    `uc', `ucfirst', `lc', `lcfirst', `hex', `oct'
        Return the result of the appropriate built-in function applied to
        the value.

    `concat(EXPR)', `append(EXPR)'
        Returns the result of the argument expression appended to the value.

    `swapcase'
        Returns a version of the value with every character's case reversed,
        i.e. a lowercase character becomes uppercase and vice versa.

    `split /PATTERN/, LIMIT'
        Returns a list of overloaded values that is the result of splitting
        (according to the built-in `split' function) the value along the
        pattern, into a number of values up to the limit.

  BOOLEAN METHODS

    `numcmp(EXPR)'
        Returns the (overloaded) value of the numerical three-way
        comparison. This method also overloads the `<=>' operator.

    `cmp(EXPR)'
        Returns the (overloaded) value of the alphabetical three-way
        comparison. This method also overloads the `cmp' operator.

    `eq(EXPR)', `ne(EXPR)', `lt(EXPR)', `gt(EXPR)', `le(EXPR)', `ge(EXPR)'
        Return the (overlaoded) boolean value of the appropriate string
        comparison. These methods also overload those operators.

    `eqi(EXPR)', `nei(EXPR)', `lti(EXPR)', `gti(EXPR)', `lei(EXPR)',
    `gei(EXPR)'
        These methods are case-insensitive versions of the above operators.

    `is_true', `is_false'
        Returns the (overloaded) boolean status of the value.

EXPORTS
    Three subroutines dealing with how properties are propagated are
    automatically exported. For an example of propagation, see the
    DESCRIPTION section above.

    `pass_on(LIST)'
        Sets (replaces) the list of properties that are passed on. There is
        only one such list for the whole mechanism. The whole property
        interface is experimental, but this one in particular is likely to
        change in the future.

    `passed_on(STRING)'
        Tests whether a property is passed on and returns a boolean value.

    `get_pass_on'
        Returns a list of names of properties that are passed on.

BUGS
    None known so far. If you find any bugs or oddities, please do inform
    the authors.

AUTHORS
    James A. Duncan <jduncan@fotango.com>

    Marcel Grunauer, <marcel@codewerk.com>

COPYRIGHT
    Copyright 2001 Marcel Grunauer, James A. Duncan. All rights reserved.

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

SEE ALSO
    perl(1), overload(3pm), Perl 6's properties.