in reply to Re^2: Mixing procedural and OO code, one file.
in thread Mixing procedural and OO code, one file.

This is for wide distribution within the organization, and I want to have as little barriers as possible to it getting used.

The installer for yours module can install the other module at the same time. That's a simple matter of putting one line in Makefile.PL.

Are you saying the easiest way to do this is to create an 'output' package and import it into both main and State::Object?

Seems simple to me:

use Logger qw( output :err_levels );
use strict; use warnings; package Logger; use Exporter qw( import ); our @EXPORT_OK = qw( LOG_ERROR LOG_VERBOSE_ERROR LOG_WARNING LOG_VERBOSE_WARNING output ); our %EXPORT_TAGS = ( err_levels => [qw( LOG_ERROR LOG_VERBOSE_ERROR LOG_WARNING LOG_VERBOSE_WARNING )], ); use constant { LOG_ERROR => 1, LOG_WARNING => 2, }; use constant { LOG_VERBOSE_ERROR => -LOG_ERROR, LOG_VERBOSE_WARNING => -LOG_WARNING, }; sub output { ... } 1;

I find it odd that control over whether the warning or error is verbose or not is in the caller's control and not a configuration item.

Update: Added code.

Replies are listed 'Best First'.
Re^4: Mixing procedural and OO code, one file.
by DStaal (Chaplain) on Feb 05, 2009 at 17:21 UTC

    One note: use constant { .. }; requires a moderately recent Perl. This has bit me in the not-to-distant past... (Just a sidenote, since it's not easy to find the error when it happens.)

    I find it odd that control over whether the warning or error is verbose or not is in the caller's control and not a configuration item.

    The idea is that the caller can define whether a particular message is part of 'verbose' or not, and the configuration will define whether (and possibly how) they are output. So you can ask for errors, warnings, or both, and get either short or verbose versions.

    This is fairly early stages in the design on this: I've got little more than a skeleton all in all. Just enough to see how it all works, not so much I can't re-organize it if I think I want to.

      I updated the code to use a tag to facilitate the import of the constants.

      One note: use constant { .. }; requires a moderately recent Perl.

      Not really.

      It works since 1.03 (Jul 2001)

      It works with Perl 5.6.0 (Mar 2000). It might work with older version too, but that's as far back as I can test.

      Perl 5.8.0 (Jul 2002) was the first version of Perl than came with a version of constant that supported this syntax.

        Around where I work, that's recent. ;)