1
1
knowhow NQPAttribute {
2
2
has $ ! name ;
3
3
has $ ! type ;
4
+ has $ ! has_type ;
4
5
has $ ! box_target ;
5
6
6
- method new (: $ name ! , : $ type , : $ box_target ) {
7
+ method new (: $ name ! , : $ box_target , * % extra ) {
7
8
my $ attr := pir::repr_instance_of__PP(self );
8
- $ attr . BUILD(: name($ name ), : type($ type ), : box_target($ box_target ));
9
+ $ attr . BUILD(: name($ name ), | % extra , : box_target($ box_target ),
10
+ : has_type(pir:: exists (% extra , ' type' )));
9
11
$ attr
10
12
}
11
13
12
- method BUILD (: $ name , : $ type , : $ box_target ) {
14
+ method BUILD (: $ name , : $ type , : $ has_type , : $ box_target ) {
13
15
$ ! name := $ name ;
14
16
$ ! type := $ type ;
17
+ $ ! has_type := $ has_type ;
15
18
$ ! box_target := $ box_target ;
16
19
}
17
20
@@ -20,7 +23,7 @@ knowhow NQPAttribute {
20
23
}
21
24
22
25
method type () {
23
- $ ! type // pir::null__P()
26
+ $ ! has_type ?? $ ! type !! pir::null__P()
24
27
}
25
28
26
29
method has_accessor () {
@@ -36,29 +39,29 @@ knowhow NQPAttribute {
36
39
}
37
40
38
41
method compose ($ obj ) {
39
- my $ long_name := ~ $ ! name ;
40
- if self . has_mutator {
41
- my $ method := pir:: substr ($ long_name , 1 );
42
- unless has_method($ obj , $ method , 0 ) {
43
- $ obj . HOW . add_method($ obj . WHAT , $ method , method ($ value ? ) {
44
- pir::setattribute__vppsp(self , $ obj . WHAT , $ long_name , $ value )
45
- if pir:: defined ($ value );
46
-
47
- pir::getattribute__ppps( self , $ obj . WHAT , $ long_name );
48
- }
49
- );
50
- }
51
- }
52
- else {
53
- my $ method := pir :: substr ( $ long_name , 2 );
54
- unless has_method ($ obj , $ method , 0 ) {
55
- $ obj . HOW . add_method( $ obj , $ method ,
56
- method () {
57
- pir::getattribute__PPPs( self , $ obj . WHAT , $ long_name );
58
- }
59
- );
60
- }
61
- }
42
+ # my $long_name := ~$!name;
43
+ # if self.has_mutator {
44
+ # my $method := pir::substr($long_name, 1);
45
+ # unless has_method($obj, $method, 0) {
46
+ # $obj.HOW.add_method($obj.WHAT, $method, method ($value?) {
47
+ # pir::setattribute__vppsp(self, $obj.WHAT, $long_name, $value)
48
+ # if pir::defined($value);
49
+ # pir::getattribute__ppps(self, $obj.WHAT, $long_name);
50
+ # }
51
+ # );
52
+ # }
53
+ # }
54
+ # else {
55
+ # my $method := pir::substr($long_name, 2);
56
+ # unless has_method($obj, $method, 0) {
57
+ # $obj.HOW.add_method ($obj, $method,
58
+ # method () {
59
+ # pir::getattribute__PPPs(self, $obj.WHAT, $long_name);
60
+ # }
61
+ # );
62
+ # }
63
+ # }
64
+ $ obj
62
65
}
63
66
64
67
# Hack to check twigil.
0 commit comments