Understanding perl use structures [closed] - perl

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am trying to understand some messy Perl where there a lot of modules that use each. We end up having everything very intertwined and in some cases, global variables are used without using what defines them (for example, A use B, B use C, C defines a variable X which A uses). It is very difficult to refactor the code this way. Are there any methods that will help me understand the structure of the code and what uses what? For what it's worth, we already use strict.

Sorry, but there is no Perl module or other generally available script that can do what your looking for. I had a similar problem once and had to write my own scripts (possibly using NYTProf eg) to parse each module and then analys the collected data externally.
Other than that you're left with commenting out all "use" statements then bring them back in one at a time, only after having done this process with any modules you bring in. A touch job, but you'll learn a lot about your code.
When you start to make changes expect unexpected failures because when you have circular use statements like this, the compilation depends on the order that code is introduced - meaning compilation errors in totally unrelated modules.
Good luck.

Related

What perl web framework to use for the old CGI based perl code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Yes, while i'm working on node.js, i still love perl, :)
The old web product is based on old perl CGI, i'm looking to the simplest way to fix XSS/Sql injection/etc. web security holes, within a week including testing, :(
So for
Catalyst
Dancer
Mason
Maypole
Mojolicious
which one should i use in the ARM platform ?
Thank you !
You have fallen foul of the primarily opinion-based off-topic categorisation, and your question will probably be closed very soon. However I think it's worth offering a few guidelines here
First of all you should absorb what is written in CGI::Alternatives as it is a reasonable summary of the subject
Next you should separate the HTML generation functionality of your existing CGI code from the interface itself, and consider replacements for each of them separately. If you were to use HTML::Tiny together with CGI::Simple then your code would have to change very little and you would have achieved better partitioning of functionality
Ideally you will move on to one of the many templating systems such as Template Toolkit, together with one of the frameworks, which is the topic of your question. In the end you will need to do a lot of research and many trials to discover how well each framework fits your requirement, in terms of both the feature list and the convenience and clarity of the API
All I can do here is say that I am very fond of the Mojolicious suite and suggest that it may be a good starting point. The API focuses on command chaining in a way similar to Ruby, and there is a Mojolicious::Plugin::CGI accessory which will allow you to execute CGI scripts unchanged during your migration
Note however that all of the frameworks that you mention, as well as several others, will have their proponents. That is why you must make the selection yourself, as such recommendations will be influenced primarily by familiarity, and without your own knowledge of the requirements of your project
Unfortunately I cannot speak to the security issues of the various options, but I hope that has helped a little

Is there any value in putting subroutines in a module if they are specific to your program? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I started coding in Perl a few years ago. Back then I thought to simplify my code and make it more manageable I would group subroutines together in .pm files. For example, subs related to generating a report would go into "Report.pm".
Now I'm looking back on my code and since the vast majority of my subs are program-specific, I'm wondering if there's any valid reasons to do it the way I did? The programs I write are generally ~8K lines of code and my code runs (always) on very powerful servers. Today, the concept of having a main .pl file plus 5 *.pm files just seems like more files to manage and now I'm wondering if I should have just put it all into a single .pl file?
I'm not familiar with Perl, but to some extent this is similar in every programming language.
I see three reasons to split program into multiple files: productivity, reuse (which is badly-disguised productivity, or at least it should be) and clarity.
You say that you have only program-specific code, so you don't gain any reuse (at least external). My experience is that almost always generic things are already in some library and most of the code is program specific. With the size of the program it gets more important to reuse "internally", but only you can know whether you repeat yourself.
Productivity (in a more manual sense) depends on tooling. If you can click on a function call and jump to its definition, even in a different file, or rename it everywhere and most important, prepare a distribution without manually going through all the files, you don't think about having multiple files as an extra chore. If you don't have those things, each extra files bring extra work.
Clarity - If you have everything in one file, it's much easier to create one huge monolith that depends on lot of things and after a while it is hard to change. If you split it into reasonable modules where you can test "leaf" modules independently, you will have a much easier time refactoring and changing when requirements change.

how to assess the quality of CPAN Perl modules? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In CPAN, a huge amount of Perl modules are available.
Which is your favourite way / method to assess the quality of a Perl module ? --- in prior to a manual test.
It seems like a rather easy question but it implies an impact. Many modules are buggy and time wasters. And it is not my intention to name a few of them to avoid an unnecessary defamation.
MetaCPAN Metrics: Rating, Bugs, Last Updated
In order to get easy access to these, try searching on metacpan.org instead of cpan.org. It displays number of open bug reports and average rating on the left-hand side, as well as telling you when the module was last updated and gives you an overview of the speed at which changes are made to the module.
You can also easily see a list of dependencies on the right, so you can look for any modules in the groundwork which are less-than-stellar. It doesn't give you any data you can't get on cpan.org, but it does put it all in one place.
Obviously, if you're working on critical infrastructure, nothing is going to replace an old-fashioned code review as you need to be confident not only in the quality of your program but in your understanding of the plumbing, but those are the metrics I usually look at first.

Recommended Scala io library [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
Improve this question
By all accounts, Scala's Source is a bit of a mess - everything I've read about it mentions resources left open, mysterious bugs...
I was wondering whether that was still the case in recent versions of Scala and, if so, what are worthy alternatives?
I've mostly heard of scala-io and scalaz-streams (and, obviously standard Java IO primitives). Did I miss anything? If anyone has experience with these or other projects, what are their respective pros and cons?
I'm inclined to go for scala-io, since I found the author's blog to be a fairly high quality source of useful of information, but I'd love to know more about the alternatives and what other people use.
Rapture IO might be worth trying.
It provides some nice DSL for managing IO resources of various kinds.
Using the package java.nio.file in Java standard library may also be simple enough if you don't require advance features. For example, to read the lines of a file into memory:
Files.readAllLines(Paths.get("file_name"), StandardCharsets.UTF_8).asScala
And to write a sequence of lines into a file:
val strs = Seq("line1", "line2", "line3")
Files.write(Paths.get("output_file"), strs.mkString("\n").getBytes())
Check
http://docs.oracle.com/javase/tutorial/essential/io/file.html
for more information.

Is there a good library in CPAN for filtering out cross-site scripting (XSS)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Is there a good library in CPAN for filtering out an textfield for all the bad things, like xss?
Your first step should always be to search and browse through the results. It looks like there are lots of potential hits. When I'm looking for something new, I browse through search results and check the docs of modules to see how clear they are and how well built the API is. I also look for reviews (some have, some don't - it's often random) and check bugs. It gives me a sense of what I'm dealing with.
If your question is "Which of these various options is best?", then I'm afraid I don't know in this case. (My initial answer may have been too general.)
Two good places to start a search of CPAN:
Search CPAN
Kobes' search
At the base level you want HTML::Entities, but which escape you chose depends on where in the DOM you're using the values. It won't help at all to html entity encode a user input if you stick it inside a <script> tag, for example.
It's pretty likely that you're using some kind of template to generate the html, so it should have a method to escape the content, HTML::Mason has <% $thing |h %>, Template::Toolkit has [% thing | html %]... but if you're just doing it in your own code you'll need to call encode_entities yourself.