#!perl use List::Util qw(any); HELP1 "adduser " => "Create an account"; sub command :Tab(adduser) ($self, $cart, $command, @) { $command eq 'adduser' or return NEXT; if ($cart->size) { return ABORT, "Create the account *before* scanning things."; } return "Name for the new account", \&username; } sub username($self, $cart, $name, @) { return REJECT, "Sorry, only A-Z a-z 0-9 _ - + / ^ * [] {} are allowed." if $name !~ /^[A-Za-z0-9_\-+\/\^*\[\]{}-]+\z/; return REJECT, "Sorry, - + / ^ * are not allowed as the first character." if $name =~ /^[-+*\/\^]/; return REJECT, "Sorry, that's too numeric to be a user name." if defined RevBank::Amount->parse_string($name); return REJECT, "That name is not available." if defined parse_user($name, 1); for my $plugin (RevBank::Plugins->new) { my $id = $plugin->id; return REJECT, "That name would clash with the '$id' plugin." if any sub { $_ eq $name }, $plugin->Tab('command'); } RevBank::Users::create( $name ); return ACCEPT; }