1. my class Encoding::Encoder::Builtin does Encoding::Encoder {
  2. has str $!encoding;
  3. has Blob $!type;
  4. has $!replacement;
  5. has int $!config;
  6. method new(Str $encoding, Blob:U $type, :$replacement, :$strict) {
  7. nqp::create(self)!setup($encoding, $type, :$replacement, :$strict)
  8. }
  9. method !setup($encoding, $type, :$replacement, :$strict) {
  10. $!encoding = $encoding;
  11. $!type := nqp::can($type.HOW, 'pun') ?? $type.^pun !! $type.WHAT;
  12. $!replacement = $replacement.defined ?? $replacement !! nqp::null_s();
  13. $!config = $strict ?? 0 !! 1;
  14. self
  15. }
  16. method encode-chars(str $str --> Blob:D) {
  17. nqp::encoderepconf($str,
  18. $!encoding,
  19. $!replacement,
  20. nqp::create($!type),
  21. $!config)
  22. }
  23. }