Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change sub to callable.
  • Loading branch information
kaare committed Jan 4, 2017
1 parent 6b4bb97 commit 416b4db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/DBDish.pm6
Expand Up @@ -20,10 +20,10 @@ role Driver does DBDish::ErrorHandling {
}

role Type {
has Sub %!Conversions{Str};
has Callable %!Conversions{Str};

method set(Str $name, Sub $convert) {
%!Conversions{$name} = $convert;
method set(Str $name, &convert) {
%!Conversions{$name} = &convert;
}
method get(Str $name) {
%!Conversions{$name} || sub (Str :$str, Str :$type-name) { $type-name($str) };
Expand Down
9 changes: 7 additions & 2 deletions t/06-types.t
Expand Up @@ -4,9 +4,13 @@ use DBDish;
plan 9;

class type-test does DBDish::Type {
method test-str(Str $value) {
$value.flip;
}

submethod BUILD {
%!Conversions{'Int'} = sub (Str $value) { Int($value) };
self.set('Str', sub (Str $value) { $value });
self.set('Str', self.^find_method('test-str'));
}
}

Expand All @@ -19,4 +23,5 @@ ok $sub = $test.get('Int');
is $sub.WHAT, Sub;
is $sub('123'), 1;
ok $sub = $test.get('Str');
is $sub('test'), 'test';
$sub.gist.say;
is $test.$sub('test'), 'tset';

0 comments on commit 416b4db

Please sign in to comment.