/**
  * Execute this action
  *
  * @param  string[] $args command line args
  * @return int exit code
  */
 public function perform($args)
 {
     if (empty($args)) {
         Console::$err->writeLine('*** Missing argument #1: Module name');
         return 2;
     }
     sscanf($args[0], '%[^@]@%s', $name, $version);
     $module = Module::valueOf($name);
     $cwd = new Folder('.');
     $vendor = new FileCollection(new Folder($cwd, $module->vendor));
     $versions = new FilteredIOCollectionIterator($vendor, new NameMatchesFilter('#^' . $module->name . '@.+#'));
     if (null === $version) {
         // No version given: Remove all installed modules, and the module reference
         if (!$vendor->findElement($module->name . '.json')) {
             Console::writeLine($module, ' not installed');
             return 1;
         }
         $this->removeAll($cwd, $versions);
         Console::writeLine('Removing module reference');
         $vendor->removeElement($module->name . '.json');
     } else {
         // Specific version given: Remove this version, if it's the last one, the
         // module reference, if not, select next possible one.
         if (!($coll = $vendor->findCollection($module->name . '@' . $version))) {
             Console::writeLine($module, ' not installed in version ', $version);
             return 1;
         }
         $active = $this->remove($cwd, $coll);
         if ($versions->hasNext()) {
             if ($active) {
                 $next = $versions->next();
                 $pth = new File('.' . $module->vendor . '.' . basename($next->getURI()) . '.pth');
                 $out = $pth->getOutputStream();
                 $base = strtr(substr($next->getURI(), strlen($cwd->getURI())), DIRECTORY_SEPARATOR, '/');
                 Console::writeLine('Select ', $pth);
                 foreach (new FilteredIOCollectionIterator($next, new ExtensionEqualsFilter('.pth')) as $found) {
                     $r = new StringReader($found->getInputStream());
                     while (null !== ($line = $r->readLine())) {
                         if ('' === $line || '#' === $line[0]) {
                             continue;
                         } else {
                             if ('!' === $line[0]) {
                                 $out->write('!' . $base . substr($line, 1) . "\n");
                             } else {
                                 $out->write($base . $line . "\n");
                             }
                         }
                     }
                 }
             }
         } else {
             Console::writeLine('Removing module reference');
             $vendor->removeElement($module->name . '.json');
         }
     }
     Console::writeLine('Done');
     return 0;
 }