Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Change the type conversion to hash association.
Allow pg types to be dynamic. This is inmportant for e.g. enums
- Loading branch information
Showing
7 changed files
with
43 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| use v6; | ||
| use Test; | ||
| use DBDish; | ||
| plan 9; | ||
| need DBDish; | ||
|
|
||
| plan 11; | ||
|
|
||
| class type-test { | ||
| has %.Converter is DBDish::TypeConverter; | ||
|
|
||
| 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, self.^find_method('test-str')); | ||
| %!Converter{Int} = sub (Str $value, $typ) { Int($value) }; | ||
| %!Converter{Str} = self.^find_method('test-str'); | ||
| } | ||
| } | ||
|
|
||
| ok my $test = type-test.new; | ||
| ok my $sub = $test.get(Int); | ||
| is $sub('123'), 123; | ||
| ok my $res = $test.Converter.convert('123', Int), 'Get the result (Int)'; | ||
| is $res, 123, 'Check it'; | ||
|
|
||
| ok my $sub = $test.Converter{Int}, 'Get the converter sub (Int)'; | ||
| is $sub('123', Int), 123, 'and then convert'; | ||
| my $int = sub ($) {1}; | ||
| ok $test.set(Int, $int); | ||
| ok $sub = $test.get(Int); | ||
| is $sub.WHAT, Sub; | ||
| is $sub('123'), 1; | ||
| ok $sub = $test.get(Str); | ||
| is $test.$sub('test'), 'tset'; | ||
| ok ($test.Converter{Int} = $int), 'Change the Int converter'; | ||
| ok $sub = $test.Converter{Int}, 'Get it back'; | ||
| is $sub.WHAT, Sub, 'Is it a sub?'; | ||
| is $sub('123'), 1, 'Does it do its job?'; | ||
|
|
||
| ok $sub = $test.Converter{Str}, 'get the Str method'; | ||
| is $test.$sub('test'), 'tset', 'and try it'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters