| 30 | | symbol example meaning |
| 31 | | ::* ::*A root; begins absolute names. |
| 32 | | :: ::A begins relative names |
| 33 | | :: ...::A separator |
| 34 | | ($expr) a subpath expanded at runtime. |
| 35 | | ..::($expr)::.. but not ..::($expr)baz::.. |
| 36 | | ::*Main The user's default namespace. |
| | 35 | Names |
| | 36 | |
| | 37 | Names are hierarchical, like filesystem path names. |
| | 38 | They start with :: . The separator is also :: . Just like / in unix. |
| | 39 | Strings can be interpolated into names by ($expr) , but must begin and |
| | 40 | end at separator boundaries. |
| | 41 | |
| | 42 | Some notable namespaces are: |
| | 43 | ::* global (root) |
| | 44 | ::MY current lexical |
| | 45 | ::*::Main the user default |
| | 46 | |
| | 47 | A name N can be used: |
| | 48 | N by itself |
| | 49 | %N:: as a hash (symbol table) |
| | 50 | $N @N %N &N to name variables |
| | 51 | |
| | 52 | The beginning of a name can be abbreviated, to make short names even simpler. |
| | 53 | example shorter rule |
| | 54 | %::A %A the starting :: can be dropped if it's not at the word beginning |
| | 55 | ::*::A ::*A root doesn't need a separator |
| | 56 | ::A A a declared name doesn't need the starting :: |
| | 57 | ::*A *A root's starting :: can be dropped where there is no confusion |
| | 58 | with unary * (such as declarations). |
| | 59 | |
| | 60 | There are a bunch of examples below. |
| 49 | | %Name symbol table |
| 50 | | %Name<$x> lookup |
| 51 | | %::* global symbol table |
| 52 | | %::*P symbol table of top-level P |
| 53 | | %P:: symbol table of some P |
| | 75 | |
| | 76 | Autoloading: |
| | 77 | |
| | 78 | The presense of names in a namespace can be faked. Or implemented |
| | 79 | lazily. If a user inquires about (defined(...)), or tries to use a |
| | 80 | variable, which is not in the symbol table, hooks are called. |
| | 81 | |
| | 82 | For SCALAR ARRAY HASH SUB METH ...: |
| | 83 | |
| | 84 | AUTO... predicates test the existance of a variable, |
| | 85 | returning undef or _any_ ref of the right type. |
| | 86 | AUTO...DEF accessors actually fetch the requested variable. |
| | 87 | |
| | 88 | [Can a package or role AUTOMETH?] |
| | 89 | |
| | 90 | |
| | 91 | Binding: |
| | 92 | |
| | 93 | := ::= |
| | 94 | # todo |
| | 95 | |
| | 96 | |
| | 97 | |
| | 98 | Here are assorted examples of names: |
| | 99 | |
| | 100 | ::A namespace name, relative |
| | 101 | ::A::B |
| | 102 | ::A::B::C |
| | 103 | ::* namespace name, absolute (::* is root) |
| | 104 | ::*A (root doesn't need a separator) |
| | 105 | ::*A::B |
| | 106 | ::*A::B::C |
| | 107 | %A:: namespace as hash; relative name |
| | 108 | %A::B:: |
| | 109 | %*:: namespace as hash; absolute name |
| | 110 | %*A:: |
| | 111 | %*A::B:: |
| | 112 | %x variable name, lexical ("%" could be any sigil $@%& etc) |
| | 113 | %A::x variable name, relative ("%" could be any sigil $@%& etc) |
| | 114 | %A::B::x ("%" could be any sigil $@%& etc) |
| | 115 | %*x variable name, absolute ("%" could be any sigil $@%& etc) |
| | 116 | %*A::x ("%" could be any sigil $@%& etc) |
| | 117 | %*A::B::x ("%" could be any sigil $@%& etc) |
| | 118 | Abbreviations used above: |
| | 119 | ::*::A ::*A (root doesn't need a separator) |
| | 120 | %::A:: %A:: (the leading :: is only needed if it starts the word) |
| | 121 | (::A::B could NOT be abbreviated A::B) |
| | 122 | %::A::x %A::x |
| | 123 | %::*::x %*x (using both) |
| | 124 | %::*::A:: %*A:: |
| | 125 | Notable namespaces: |
| | 126 | ::MY current lexical namespace |
| | 127 | %MY:: as hash |
| | 128 | %MY::x a variable in ("%" could be any sigil $@%& etc) |
| | 129 | ::*Main default user namespace |
| | 130 | %*Main:: as hash |
| | 131 | %*Main::x a variable in ("%" could be any sigil $@%& etc) |
| | 132 | Runtime interpolation: |
| | 133 | ::("A") ::A |
| | 134 | ::("A::B") ::A::B |
| | 135 | ::("A::")B # ILLEGAL |
| | 136 | ::("A")::B ::A::B |
| | 137 | ::A::("B") ::A::B |
| | 138 | ::A::("B")::C ::A::B::C |
| | 139 | ::("*") ::* |
| | 140 | ::("*A") ::*A |
| | 141 | ::("*::A") ::*A |
| | 142 | %::("A"):: %A:: |
| | 143 | %::("A::") # ILLEGAL |
| | 144 | %::("A::x") %A::x ("%" could be any sigil $@%& etc) |
| | 145 | ::($expr) a namespace name |
| | 146 | ::($e1)::($e2) a namespace name |
| | 147 | %::($expr):: a namespace used as a hash |
| | 148 | %::($expr) a variable name ("%" could be any sigil $@%& etc) |
| | 149 | Using a namespace hash (a symbol table): |
| | 150 | %P:: namespace P as a hash (a symbol table) |