Revision 343738383139 () - Diff

Link to this snippet: https://friendpaste.com/2kF2g0nQpVE0GzrKaEE7HA
Embed:
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
15:39 ~/g/code/p6/crypt$ nom handles.pl
foo(a, b)
bar(A, B)
DEBUG: Methods are:
(submethod BUILD(User , Mu *%_) { ... }, method bar(User , $arg1, $arg2, Mu *%_) { ... }, method foo(Mu , |$c, Mu *%_) { ... })
Method BUILD:
- param '', type: Userall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
Method bar:
- param '', type: Userall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '$arg1', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: no, pos: yes
- param '$arg2', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: no, pos: yes
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
Method foo:
- param '', type: Muall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '$c', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: yes, parcel: no, slurpy: no, optional: no, invocant: no, pos: no
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
DEBUG: Commands are:
("BUILD" => ().list.item, "bar" => ("arg1", "arg2").list.item, "foo" => ().list.item).hash
Commands:("BUILD" => ().list.item, "bar" => ("arg1", "arg2").list.item, "foo" => ().list.item).hash
15:40 ~/g/code/p6/crypt$ perl6 handles.pl
foo(a, b)
bar(A, B)
DEBUG: Methods are:
(submethod BUILD(User , Mu *%_) { ... }, method bar(User , $arg1, $arg2, Mu *%_) { ... }, method foo(Mu , |$c, Mu *%_) { ... })
Method BUILD:
- param '', type: Userall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
Method bar:
- param '', type: Userall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '$arg1', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: no, pos: yes
- param '$arg2', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: no, pos: yes
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
Method foo:
- param '', type: Muall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: no, parcel: no, slurpy: no, optional: no, invocant: yes, pos: yes
- param '$c', type: Anyall(), type_captures: , rw: no, copy: no, named: no, named_names: ().list, capture: yes, parcel: no, slurpy: no, optional: no, invocant: no, pos: yes
- param '%_', type: Muall(), type_captures: , rw: no, copy: no, named: yes, named_names: ().list, capture: no, parcel: no, slurpy: yes, optional: no, invocant: no, pos: no
DEBUG: Commands are:
("BUILD" => ().list.item, "bar" => ("arg1", "arg2").list.item, "foo" => ("c",).list.item).hash
Commands:("BUILD" => ().list.item, "bar" => ("arg1", "arg2").list.item, "foo" => ("c",).list.item).hash
15:40 ~/g/code/p6/crypt$ cat handles.pl
#! /usr/bin/env perl6

use v6;

class Engine {
method foo($arg1, $arg2) { say "foo($arg1, $arg2)"; }
}

class User {
has $!engine handles <foo>;

submethod BUILD() { $!engine = Engine.new; }

method bar($arg1, $arg2) { say "bar($arg1, $arg2)"; }
}

my User $u .= new;

$u.foo('a', 'b');
$u.bar('A', 'B');

say "Commands:", objCommands($u).perl;

sub objCommands($obj) {
say "DEBUG: Methods are:\n", $obj.^methods.perl;
sub params($method) {
say "Method {$method.name}:";
for $method.signature.params {
say "- param '{.name}'",
", type: {.type.perl}",
", constraints: {.constraints}",
", type_captures: {.type_captures}",
# RAKUDO: NYI 2012-07-15
#", read_only: {.read_only ?? 'yes' !! 'no'}",
", rw: {.rw ?? 'yes' !! 'no'}",
", copy: {.copy ?? 'yes' !! 'no'}",
", named: {.named ?? 'yes' !! 'no'}",
", named_names: {.named_names.perl}",
", capture: {.capture ?? 'yes' !! 'no'}",
", parcel: {.parcel ?? 'yes' !! 'no'}",
", slurpy: {.slurpy ?? 'yes' !! 'no'}",
", optional: {.optional ?? 'yes' !! 'no'}",
", invocant: {.invocant ?? 'yes' !! 'no'}",
#", multi_invocant: {.multi_invocant ?? 'yes' !! 'no'}",
", pos: {.positional ?? 'yes' !! 'no'}"
;
}

$method.signature.params
==> grep { .positional && !.invocant }
==> map { .name.substr(1) }
}
my %commands = map { $^m.name => params($m) }, $obj.^methods;

say "DEBUG: Commands are:\n", %commands.perl;

return %commands;
}
15:41 ~/g/code/p6/crypt$ perl6 --version
This is perl6 version 2012.06 built on parrot 4.5.0 revision 0
15:45 ~/g/code/p6/crypt$ nom --version
This is perl6 version 2012.06-87-g499cc68 built on parrot 4.5.0 revision RELEASE_4_5_0
15:45 ~/g/code/p6/crypt$