You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ppcs/ppc0022-metaprogramming.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,27 +33,17 @@ The get-like functions come in pairs, consisting of a function named `get_...` a
33
33
34
34
It is currently still an undecided question on what ought to be the correct behaviour for `add`-like functions when asked to create something that already exists, or the `remove`-like functions when asked to remove something that doesn't exist. It may be solved by something similar to above, where there are two differently-named functions that differ in that case. As yet there aren't any particularly compelling solutions.
35
35
36
-
### Functions to operate on Packages
36
+
### Methods to operate on Packages
37
37
38
-
These are functions to create, manipulate, and inspect packages themselves.
38
+
These are methods to create, manipulate, and inspect packages themselves. Packages are represented by instances in the class `meta::package`.
39
39
40
-
#### `get_package`
40
+
#### `get`
41
41
42
42
```perl
43
-
$metapackage = meta::get_package($name);
43
+
$metapackage = meta::package->get($name);
44
44
```
45
45
46
-
Returns a meta-package object instance to represent the named package, if such a package exists. If not an exception is thrown.
47
-
48
-
[[TODO: Decide whether "all packages exist", and thus this can never fail]]
49
-
50
-
#### `add_package`
51
-
52
-
```perl
53
-
$metapackage = meta::add_package($name);
54
-
```
55
-
56
-
Creates a new package of the given name, and returns a meta-package object instance to represent it.
46
+
Returns a meta-package object instance to represent the named package. As conceptually all packages exist, it will be implicitly created if necessary.
Returns true in each of the four cases where the object represents the given type of symbol, or false in the other three cases.
174
+
Returns true in each of the five cases where the object represents the given type of symbol, or false in the other four cases.
185
175
186
176
These methods should not be considered an exhaustive selection. There may be object types to represent other glob slots such as filehandles, formats, and so on. As more types are defined, more methods would be added to distinguish them.
187
177
188
178
### Methods on Meta-Glob Objects
189
179
190
180
These methods are available on any meta-symbol object that represents a glob - i.e. one whose sigil is "\*".
191
181
182
+
#### `get`
183
+
184
+
```perl
185
+
$metaglob = meta::glob->get($name);
186
+
```
187
+
188
+
Returns a meta-glob object instance to represent the named glob from a fully-qualified name, if it exists. If not an exception is thrown.
189
+
192
190
#### `can_scalar`, `get_scalar`
193
191
194
192
```perl
@@ -362,6 +360,6 @@ It may be useful to add support for these kinds of abilities somewhere in core p
362
360
363
361
## Copyright
364
362
365
-
Copyright (C) 2022-2023, Paul Evans.
363
+
Copyright (C) 2022-2024, Paul Evans.
366
364
367
365
This document and code and documentation within it may be used, redistributed and/or modified under the same terms as Perl itself.
0 commit comments