Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Location of 'use' statements (tye)

by tye (Sage)
on Apr 18, 2003 at 20:55 UTC ( #251539=note: print w/replies, xml ) Need Help??

in reply to Location of 'use' statements

package FooBar; ## Always used: use strict; use warnings; ## Other modules: require Some::OO::Module; use Some::Function::Module qw( Func1 Func2 ); ## Setup of this module: use base 'Quux'; use vars qw( $VERSION @EXPORT_OK ); $VERSION= 1.001; @EXPORT_OK= qw( ... ); ## Globals: use vars qw( $Master ); $Master= ...; use constant _IdNo => 0; use constant _Name => 1; use constant _Pos => 2; # Gee, we need "use enum" (:

with a general tendency to put shorter items before longer items first.

                - tye

Replies are listed 'Best First'.
Re^2: Location of 'use' statements (mine)
by Aristotle (Chancellor) on Apr 19, 2003 at 15:40 UTC
    This is very close to what I do. I think of strict and warnings as part of an extended shebang line. Exporter is ugly so I avoid it wherever possible; though when I use it, I tend not to treat it and its globals specially. Finally, I reserve require solely for deferred loading of modules. So I arrive at a layout like this:
    #!/usr/bin/perl use strict; use warnings; package FooBar; use Some::OO::Module (); use Some::Function::Module qw( Func1 Func2 ); use base 'Quux'; use vars qw($VERSION); $VERSION= 1.001; use constant _IdNo => 0; use constant _Name => 1; use constant _Pos => 2;

    Makeshifts last the longest.

Re: Re: Location of 'use' statements (tye)
by Anonymous Monk on Apr 21, 2003 at 19:24 UTC
    This is pretty much what I do, with the following differences:
    package Blah; use strict; =HEAD1 NAME ... =cut BEGIN { # If I have one use XXX; # as required here } # pragma level 'use's use vars qw(...); # Core modules # CPAN modules # local modules # globals and initializing assignments # actual code at this point
    I personally prefer the POD at the top, since it encourages me to write it first and update it first. Keeping it in front of my face as the first thing I see when the editor opens the file helps keep that positive guilty feeling of "you didn't update the POD, did you?" going, with the result that I actually do update it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://251539]
[choroba]: Yeah, let's ban dot in INC, but add glob to it!
[Corion]: choroba: Well, at least the above is user-defined, not implicitly by Perl ;)
LanX globalization is evil! Lets Perlxit!
[stevieb]: "Yeah, let's ban dot in INC, but add glob to it!" LOL!!!

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2017-01-19 15:40 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (170 votes). Check out past polls.