← Back to index

lib/BDD/Behave/Formatter/Registry.rakumod

31 / 32 lines covered (96.9%)

1use BDD::Behave::Formatter;2use BDD::Behave::Formatter::Documentation;3use BDD::Behave::Formatter::HTML;4use BDD::Behave::Formatter::JSON;5use BDD::Behave::Formatter::JsonEvents;6use BDD::Behave::Formatter::JUnit;7use BDD::Behave::Formatter::Progress;8use BDD::Behave::Formatter::TAP;9use BDD::Behave::Formatter::Tree;1011class BDD::Behave::Formatter::Registry {12  my %registry;1314  method register(Str $name, $class) {15    die "Formatter '$name' has already been registered"16      if %registry{$name}:exists;17    die "Formatter class for '$name' must compose BDD::Behave::Formatter"18      unless $class.^does(BDD::Behave::Formatter);19    %registry{$name} = $class;20  }2122  method registered(Str $name --> Bool) {23    %registry{$name}:exists;24  }2526  method names(--> List) {27    %registry.keys.sort.List;28  }2930  method lookup(Str $name) {31    die "Unknown formatter: '$name' (available: {self.names.join(', ')})"32      unless %registry{$name}:exists;33    %registry{$name};34  }3536  method create(Str $name, *%args) {37    my $class = self.lookup($name);38    $class.new(|%args);39  }4041  method reset {42    %registry = ();43    self.register('documentation', BDD::Behave::Formatter::Documentation);44    self.register('html',          BDD::Behave::Formatter::HTML);45    self.register('json',          BDD::Behave::Formatter::JSON);46    self.register('json-events',   BDD::Behave::Formatter::JsonEvents);47    self.register('junit',         BDD::Behave::Formatter::JUnit);48    self.register('progress',      BDD::Behave::Formatter::Progress);49    self.register('tap',           BDD::Behave::Formatter::TAP);50    self.register('tree',          BDD::Behave::Formatter::Tree);51  }52}5354BDD::Behave::Formatter::Registry.register('documentation', BDD::Behave::Formatter::Documentation);55BDD::Behave::Formatter::Registry.register('html',          BDD::Behave::Formatter::HTML);56BDD::Behave::Formatter::Registry.register('json',          BDD::Behave::Formatter::JSON);57BDD::Behave::Formatter::Registry.register('json-events',   BDD::Behave::Formatter::JsonEvents);58BDD::Behave::Formatter::Registry.register('junit',         BDD::Behave::Formatter::JUnit);59BDD::Behave::Formatter::Registry.register('progress',      BDD::Behave::Formatter::Progress);60BDD::Behave::Formatter::Registry.register('tap',           BDD::Behave::Formatter::TAP);61BDD::Behave::Formatter::Registry.register('tree',          BDD::Behave::Formatter::Tree);