Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow passing initial attribute values to .new
  • Loading branch information
sorear committed Dec 28, 2010
1 parent dc2fc3b commit c2857c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/Kernel.cs
Expand Up @@ -1708,9 +1708,16 @@ public class Kernel {

for (int i = mro.Length - 1; i >= 0; i--) {
foreach (DynMetaObject.AttrInfo a in mro[i].local_attr) {
IP6 val = a.init == null ? AnyP :
RunInferior(a.init.Invoke(GetInferiorRoot(),
Variable.None, null)).Fetch();
IP6 val;
Variable vx;
if (a.publ && args.TryGetValue(a.name, out vx)) {
val = vx.Fetch();
} else if (a.init == null) {
val = AnyP;
} else {
val = RunInferior(a.init.Invoke(GetInferiorRoot(),
Variable.None, null)).Fetch();
}
n.SetSlot(a.name, NewRWScalar(AnyMO, val));
}
}
Expand Down
8 changes: 8 additions & 0 deletions test2.pl
Expand Up @@ -12,6 +12,14 @@
is $str, '2413', 'INIT blocks run in correct order';
}

{
my class X3 {
has $.a;
}
my $x = X3.new(a => 5);
is $x.a, 5, 'Attribute values can be passed in constructors';
}

#is $?FILE, 'test.pl', '$?FILE works';
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';

Expand Down

0 comments on commit c2857c1

Please sign in to comment.