Skip to content

Commit d040ecd

Browse files
committed
refactor ind-ref() method
1 parent 0ca2872 commit d040ecd

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

lib/PDF/COS/Tie.rakumod

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ my constant $Lock = Lock.new;
77
#| generate an indirect reference to ourselves
88
method ind-ref returns IndRef {
99
given $.obj-num {
10-
$_
11-
?? ($_ < 0
12-
?? die "indirect object has not been allocated"
13-
!! :ind-ref[ $_, $.gen-num ]
14-
)
15-
!! die "not an indirect object";
10+
die "not an indirect object" unless .so;
11+
die "indirect object has not been allocated"
12+
if $_ < 0;
13+
14+
:ind-ref[ $_, $.gen-num ]
1615
}
1716
}
1817

@@ -131,11 +130,6 @@ my class COSAttr {
131130
|| ($!type ~~ Associative[Mu] && $lval ~~ Hash) {
132131
self!tie-container: $lval, :$check;
133132
}
134-
elsif $lval.isa(array) && $!type ~~ Positional[Numeric] {
135-
# assume numeric. not so easy to type-check atm
136-
# https://github.com/rakudo/rakudo/issues/4485
137-
# update: fixed as of Rakudo 2021.08
138-
}
139133
else {
140134
my \of-type = $!decont ?? $!type.of !! $!type;
141135
unless $lval ~~ of-type {
@@ -151,7 +145,8 @@ my class COSAttr {
151145
}
152146
$lval;
153147
}
154-
multi method tie($lval is rw, :$check) is rw {
148+
149+
multi method tie($lval is rw, :check($)) is rw {
155150
$Lock.protect: {
156151
$lval.obj-num //= -1
157152
} if $.is-indirect && $lval ~~ PDF::COS;

t/indobj-array.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ $cs[1] = { :WhitePoint[1.0, 1.0, 1.0] };
5151
is $cs.Subtype, 'Lab', 'tied index [0]';
5252
is-json-equiv $cs.Dict, { :WhitePoint[1.0, 1.0, 1.0] }, 'tied index [1]';
5353
ok $cs.Dict ~~ ColorSpaceDict, 'tied index "does" attribute';
54-
is $cs.Dict.yay, 42, 'tied index "does" attribute';
54+
is $cs.Dict.yay, 42, 'tied index method call';
5555
lives-ok {$cs.Subtype = 'CalRGB'}, 'tied index assignment';
5656
is $cs.Subtype, 'CalRGB', 'tied index fetch';

t/indobj-dict.t

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ ind-obj-tests(
3131
);
3232
3333
ind-obj-tests(
34-
:ind-obj[29, 0, :dict{ P => :ind-ref[142, 0],
35-
S => :name<Link>,
36-
K => :array[ :ind-ref[207, 0],
37-
:dict{Type => :name<OBJR>,
38-
Pg => :ind-ref[216, 0],
39-
Obj => :ind-ref[233, 0]},
34+
:ind-obj[29, 0,
35+
:dict{ P => :ind-ref[142, 0],
36+
S => :name<Link>,
37+
K => :array[ :ind-ref[207, 0],
38+
:dict{ Type => :name<OBJR>,
39+
Pg => :ind-ref[216, 0],
40+
Obj => :ind-ref[233, 0]},
4041
]},
4142
],
4243
:class(PDF::COS::Dict),
@@ -47,7 +48,7 @@ ind-obj-tests(
4748
:Pg{ :ind-ref[ 216, 0 ] },
4849
:Obj{ :ind-ref[ 233, 0 ] },
4950
}
50-
] },
51+
] },
5152
);
5253
5354
use PDF::COS::Tie;

0 commit comments

Comments
 (0)