in reply to Re^5: can't import using exporter
in thread can't import using exporter
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: can't import using exporter
by Corion (Patriarch) on Mar 14, 2012 at 08:26 UTC | |
Extraordinary claims require extraordinary evidence. So far, all you have shown are two snippets that don't compile and a huge program that you obviously did not care to cut down to the problem. I've reduced your program to the following, self-contained program and noted where I added BEGIN blocks to make all symbols appear in the order which use would make appear them in as well:
It behooves you well to put more effort into making your findings reproducible, especially when nobody else seems to be able to reproduce your problem. Also, you may be interested in App::fatpacker, which packs a script and its modules into one monolithic file. | [reply] [d/l] |
by perl-diddler (Chaplain) on Mar 25, 2013 at 17:54 UTC | |
No BEGIN's in sight, and a natural 'use module' syntax the same as one would use them if they were in separate files. A few other things would be simpler as well, but they aren't in a form to be published yet... I do learn... using mem with Exporter as I did above, also exports the prototypes. May not be perfect, but looks tidier than using BEGIN blocks and the modules have the benefit of being easily put into separate files with no code changes. Better? | [reply] [d/l] |
by tobyink (Canon) on Mar 26, 2013 at 09:54 UTC | |
Personally I'd do this:
I don't have any problem with the BEGIN block. I'd always wrap inline packages in braces anyway, so it's just five extra letters before the opening brace. If I want to factor out MyUtils into a separate file, it's just a matter of cutting everything inside the braces and pasting it into MyUtils.pm; then replace the now empty BEGIN {} block with use MyUtils;. Easy. (And if I was being a perfectionist, I could remove no thanks; from MyUtils.pm as it becomes superfluous.)
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
| [reply] [d/l] [select] |
by perl-diddler (Chaplain) on Mar 27, 2013 at 23:24 UTC | |
| |
|
Re^7: can't import using exporter
by chromatic (Archbishop) on Mar 14, 2012 at 15:35 UTC | |
I have programs with 10 modules in 300 lines, and I should break them into 30 line modules each just because perl is broken? Perl is working exactly as documented. There's at least one question a week here about how this all works, and every time the answer is the same. I wanted 'use module' not try to include a module if it was in the same file... How is that to work? Is the compiler to guess that subsequent code in the file will declare a package? Is the compiler to process the entire file once, looking for package statements, and only then start compiling the code? You don't put such things with dependent functionality in multiple files or your development becomes a nightmare finding what file you are supposed to be in. Sure I do, and I don't have these nightmare debugging problems you do. | [reply] [d/l] |
|
Re^7: can't import using exporter
by afoken (Chancellor) on Mar 14, 2012 at 20:17 UTC | |
Just a raw guess: Your "version control system" is called copy or cp and it does not scale to more than one file per project. Do you still live in the 1960s? Learn about git and subversion, both will solve that problem, and both scale to more source files than you ever need to use. Welcome to the 21st century! Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
by perl-diddler (Chaplain) on Mar 15, 2012 at 08:22 UTC | |
Can you explain how you arrived at such a nonsensical conclusion? I've tried splitting a project early on into modules, it was a constant bother trying to find where a routine was -- in this window or that window -- is a window with that file even open? 'edit' -- oops -- file is being doubly diddled -- half the time on my other machine ---- so it's not listed with the same group as the other files... but those are minor oopses.. The time wasted finding functions that need to be updated or interfaces that need to be updated/changed over multiple files because they are just being fleshed out and not really really to be split -- or really weren't designed to exist independently, but were, because perl can't easily have multiple classes in 1 file (as is demonstrated in the **beginner** books on perl OOP (Intermediate Perl).). The introduction to classes by the experts doesn't demonstrate using "use" to use other Class objects. It shows them all in one file. That's the starting point that almost nothing follows afterwards. Yet that's the first book (or it's predecessor by a different title), on perl classes and packages that someone would be likely to read. Yet nothing in perl works that way. You don't see a problem with that? Why doesn't anyone program the way Schwartz & bdfoy, and t.phoenix demonstrated? Do Schartz and bdFoy know nothing about perl. Why would the perl community support a perl that burns anyone who programs they way Schwartz and bdFoy taught? That's not to say they use that paradigm for everything, but for Dog says bark, and Cow says moo, separating things into 5 separate files would turn off anyone.
| [reply] |
by chromatic (Archbishop) on Mar 15, 2012 at 08:39 UTC | |
perl can't easily have multiple classes in 1 file Sure it can. I do it frequently. I don't export stuff from classes, and I don't export stuff from packages in the same file. That way lies madness. Why would the perl community support a perl that burns anyone who programs they way Schwartz and bdFoy taught? Your conclusion does not follow from your premises. | [reply] |
by Anonymous Monk on Mar 15, 2012 at 09:08 UTC | |
Why would the perl community support a perl that burns anyone who programs they way Schwartz and bdFoy taught? Can you post the code what you originally posted in can't import using exporter please? Maybe brian_d_foy and merlyn can tells us if that is what they teach (i wouldn't know what they teach). | [reply] |
by perl-diddler (Chaplain) on Mar 15, 2012 at 19:22 UTC | |