Subject: [1.8.0] perl/Git.pm: moving away from using Error.pm module

From: Jakub Narebski <[email-masked]>
Date: Sun, 20 Feb 2011 23:46:33 +0100

Proposal:

Replace use of Error.pm module in Git.pm with either Exception::Class
based error class, or using 'carp'/'croak' from Carp, or both by adding 
an option to set error handler in 'Git' class (like e.g. in 'CHI' 
module on CPAN).

While at it, if we are to require some extra non-core module, instead
of using 'private-<module>.pm', use more standard 'inc/' directory
(i.e. 'inc/<module>.pm').

Also get rid of git_cmd_try - encourage to use TryCatch or Try::Tiny
instead, or even 'eval { ... }' as a way to catch thrown exceptions.

Rationale:

An extract from the Error.pm documentation: 

  Using the "Error" module is *no longer recommended* due to the
  black-magical nature of its syntactic sugar, which often tends to
  break. Its maintainers have stopped actively writing code that uses
  it, and discourage people from doing so.

"SEE ALSO" section therein mentions the following possible replacements:

  See Exception::Class for a different module providing Object-Oriented
  exception handling, along with a convenient syntax for declaring
  hierarchies for them. It doesn't provide Error's syntactic sugar of
  `try { ... }, catch { ... }`, etc. which may be a good thing or a bad
  thing based on what you want. (Because Error's syntactic sugar tends
  to break.)

  Error::Exception aims to combine Error and Exception::Class "with
  correct stringification".

  TryCatch and Try::Tiny are similar in concept to Error.pm only
  providing a syntax that hopefully breaks less.

Unfortunately, neither of those modules is in core (well, neither is 
Error.pm).

Risks:

Out of git commands and helpers implemented in Perl and using Git.pm
module, only git-svn.perl uses 'try_git_cmd' directly.  git-send-email
uses 'eval { ... }' to catch exceptions thrown by ->repository() 
constructor; perhaps other scripts do the same.  There is some risk of 
breaking git with this change...

Third party modules and scripts might have also depend on Git.pm using 
Error.pm... though I wonder how many of Perl scripts use Git instead of 
for example Git::Wrapper or other git-related Perl module from CPAN.

Migration plan:

I don't really have migration plan yet, because  I amnot sure what 
solution  should be implemented.

1. One possible solution would be to just replace Error with 
Exception::Class (or Git::Exception based in this class), and leave 
everything else as close to current state as possible.  Removing 
try_git_cmd would be second step...

2. Another solution would be to use 'on_error' to set error handler,
with support for 'die'/'croak', Error and Exception::Class based 
exceptions, with default to 'croak'.  In this case we wouldn't need any 
extra module, but testing structural exceptions would be harder.
We would have to replace try_git_cmd with eval, or Try::Tiny.

3. Yet another would be to leave Git module as it is now, and create
new modules: Git::Cmd, Git::Repo, Git::Config etc.

-- 
Jakub Narebski
Poland