CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
make perl script monolithic

 



schnick
New User

Oct 12, 2011, 12:52 AM

Post #1 of 8 (1750 views)
make perl script monolithic Can't Post

Hi,

probably there is already a thread about this topic - but I can't find it :(

I'm searching for a tool which scans my perl script and kicks out the use lines by copying the used (and only the used ) functions from a module into the script.

I'm talking about scripts which use just modules, which are not linked to DLLs, or LIBs, or similar stuff... But they can use other modules of this kind...

Perhaps someone can just name the thread which is already somewhere out there... ;)

thanks
schnick


rovf
Veteran

Oct 12, 2011, 3:41 AM

Post #2 of 8 (1749 views)
Re: [schnick] make perl script monolithic [In reply to] Can't Post


Quote
copying the used (and only the used ) functions from a module into the script.


Maybe you can elaborate a bit:

Assuming that you have a module Foo.pm


Code
#-------------------------------------------------------------------- 
# This is Foo.pm
sub bar {}
sub baz {}
sub foul {}
sub unneeded {}
#---------------------------------------------------------------------


and a program App.pl


Code
#--------------------------------------------------------------------- 
# This is App.pl
use Foo;
Foo::bar();
eval { Foo::baz() };
my $x='Foo:f';
eval $x.'oul()';
#---------------------------------------------------------------------


how should your "expanded" code look like?


schnick
New User

Oct 12, 2011, 6:21 AM

Post #3 of 8 (1747 views)
Re: [rovf] make perl script monolithic [In reply to] Can't Post

Hi rovf,

the expanded code should look somehow like:

App.pl

Code

#---------------------------------------------------------------------
# This is App.pl
##use Foo; # commented out by 'expander'
sub bar {} # inserted automaticaly by 'expander' from Foo
sub baz {} # inserted automaticaly by 'expander' from Foo
bar();
eval { baz() };
my $x='Foo:f'; ## (*)
eval $x.'oul()'; ## (*)
#---------------------------------------------------------------------

you are right, I haven't thought about stuff like this (*) :(
Probably because I don't have such things in my code - for that reason, strings can stay the same...
But you already showed me, that this problem is not as trivial as I thought :(

cheers
schnick

(This post was edited by schnick on Oct 12, 2011, 6:29 AM)


rovf
Veteran

Oct 12, 2011, 7:06 AM

Post #4 of 8 (1742 views)
Re: [schnick] make perl script monolithic [In reply to] Can't Post

Even if you don't do this in *your* code, you are very likely include modules which you haven't written by yourself (for example, Perl standard modules, and you likely can't say for sure that they don't do such tricks.

Moreover, how would you resolve this?


Code
# Module X.pm 
package X;
use Exporter;
our @EXPORT = qw(foo);
our @EXPORT_OK = "baz";
sub foo {};
sub bar {};
sub baz {};



Code
# Module Y.pm 
package Y;
use Exporter;
use X qw(); # import nothing
our @EXPORT_OK = qw/foo bar baz/;
sub foo {};
sub bar { X::baz() }
sub baz {}



Code
# Your file App.pl 
use X;
use Y 'bar';
foo();


You would have to determine that you need only X::foo, X::baz and Y::bar, but none of the other functions.


schnick
New User

Oct 13, 2011, 12:03 AM

Post #5 of 8 (1729 views)
Re: [rovf] make perl script monolithic [In reply to] Can't Post

yes, you're right - it's not trivial!
think i'll do my stuff manually :(

thanks for pointing out the problems.

cheers
schnick


rovf
Veteran

Oct 13, 2011, 6:07 AM

Post #6 of 8 (1726 views)
Re: [schnick] make perl script monolithic [In reply to] Can't Post

Of course the question remains *why* on earth you want to do it....


schnick
New User

Oct 14, 2011, 6:06 AM

Post #7 of 8 (1709 views)
Re: [rovf] make perl script monolithic [In reply to] Can't Post

that was because, we working in seperated teams, and also using own 'team-modules' - know we had a functionality which was interesting for another team and we want give them the code to do this particular thing without giving them all our modules...


rovf
Veteran

Oct 14, 2011, 6:15 AM

Post #8 of 8 (1707 views)
Re: [schnick] make perl script monolithic [In reply to] Can't Post

In this case, it would make more sense IMO to put the functionality you want to give to other team members, in a separate module. This has also the advantage that instead of few big modules, you get many small ones.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives