Thanks for the various thoughts. I appreciate, if not fully understand, the technicalities about exactly when this is an "object" and whether or not it's really a "constructor" if I leave midway.
I don't have any other OO background, so my approach to this was a DWIW one. The functionality of every program that will use this module involves having a user logged in with some info in a session; if the user isn't logged in there's no point going further. When, in my original calling program, I say
my $book = MyPackage->new( # stuff );
, my purpose is not "to create an object", it's "get started, with whatever that entails", and if that entails logging the user in, so be it. Throwing an exception seems to force me to add an extra step to every single program that uses this module; instead of the above line, I now have to say something like
my $book = MyPackage->new( # stuff );
print CGI::redirect(-uri=>"login.cgi?msg=$book->{error_msg}")
unless $book->{login_successful};
or whatever, i.e. adding an extra line of identical code to every program.
Indeed, in practice it might even be longer, since in some circumstances I need to check whether the user has the right access level. Then I'll have yet another similar or identical line to every program:
print CGI::redirect(-uri=>"login.cgi?msg=$book->{no_access}")
if $book->{user_access_level} < $book->{required_access_level};
I had wanted to put the code in the module, instead of the programs, specifically to avoid this. But if this is bad style, then it's bad style; the reason I asked is because I thought it might be, and I'll do it by throwing exceptions instead.