Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't block exporter with use_ok #41

Closed
toddr opened this issue Jul 14, 2010 · 7 comments
Closed

Can't block exporter with use_ok #41

toddr opened this issue Jul 14, 2010 · 7 comments
Labels

Comments

@toddr
Copy link
Contributor

toddr commented Jul 14, 2010

I've got a unit test that parses for all my modules in a LARGE project and does a use_ok($module) on them. The problem is that some of the modules (legacy) export the same methods.

What I would like to do is to have use_ok do a "use module ()" this is not possible at present.

What I'm envisioning is this syntax, which should be meaningless in all other contexts: use_ok($module, undef) causes use $module ();

I've attached a patch for this. I'll provide tests if you're willing to accept the patch.

@toddr
Copy link
Contributor Author

toddr commented Jul 14, 2010

@schwern
Copy link
Contributor

schwern commented Jul 14, 2010

Thanks for the work. require_ok is equivalent to what you want. use Some::Module (); is equivalent to BEGIN { require Some::Module } but use_ok doesn't happen at BEGIN time so you just want to do a require.

I'm disinclined towards the special undef syntax. It would cause odd behavior should you do use_ok $module, $import and $import is accidentally undefined.

What would be nice is a doc patch to use_ok saying the above, that if you want to test use Module () just do require_ok "Module".

@toddr
Copy link
Contributor Author

toddr commented Jul 16, 2010

require_ok doesn't call import. doesn't import get called with use $module ()?

@schwern
Copy link
Contributor

schwern commented Jul 16, 2010

No, that's the whole point of the empty parens. From perldoc -f use...

If you do not want to call the package's "import" method (for
instance, to stop your namespace from being altered),
explicitly supply the empty list:

  use Module ();

That is exactly equivalent to

  BEGIN { require Module }

@toddr
Copy link
Contributor Author

toddr commented Jul 16, 2010

my bad. Stupid patch then. I'll send you a doc patch in thanks for you pointing out my stupidity.

@toddr
Copy link
Contributor Author

toddr commented Aug 26, 2010

A pull request has been sent. it should just be a cherry-pick of sha 5be859f

@schwern
Copy link
Contributor

schwern commented Sep 11, 2010

Done and in 0.97_01.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants