The two BEGIN blocks in your second snippet will do the same thing as the three BEGIN blocks in your first snippet, but they are not equivalent.
- Compile first BEGIN block.
- Compile require Test::More;.
- Compile import Test::More;.
- Execute first BEGIN block.
- Execute require Test::More;.
- Execute import Test::More;.
- Compile second BEGIN block.
- Compile use_ok 'Module::A'.
- Execute second BEGIN block.
- Execute use_ok 'Module::A'.
- Compile third BEGIN block.
- Compile use_ok 'Module::B'.
- Execute third BEGIN block.
- Execute use_ok 'Module::B'.
- Compile done_testing;.
- End of compile phase.
- Execute done_testing;.
vs
- Compile first BEGIN block.
- Compile require Test::More;.
- Compile import Test::More;.
- Execute first BEGIN block.
- Execute require Test::More;.
- Execute import Test::More;.
- Compile second BEGIN block.
- Compile use_ok 'Module::A'.
- Compile use_ok 'Module::B'.
- Execute second BEGIN block.
- Execute use_ok 'Module::A'.
- Execute use_ok 'Module::B'.
- Compile done_testing;.
- End of compile phase.
- Execute done_testing;.
Or in short,
- ...
- Compile use_ok 'Module::A'.
- Execute use_ok 'Module::A'.
- Compile use_ok 'Module::B'.
- Execute use_ok 'Module::B'.
- ...
vs
- ...
- Compile use_ok 'Module::A'.
- Compile use_ok 'Module::B'.
- Execute use_ok 'Module::A'.
- Execute use_ok 'Module::B'.
- ...
In the first, use_ok 'Module::A' could have an effect on how use_ok 'Module::B' is compiled. In the second, it can't.
I agree with Corion, though. There's no reason to use use_ok.
use Test::More tests => 1;
use Module::A;
use Module::B;
pass("Loading modules");
1;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.