📜 ⬆️ ⬇️

What a Perl novice developer should know about pearl barley infrastructure

Due to the fact that the shortage of personnel in the IT industry is large, and there are very few perlovikov (and those that are, they already want to be tech readers and get a lot of money), many offices are happy to take on capable young people to become perlovikov.
The company in which I am currently working also thought about it and I remembered my idea to sketch a kind of cheat sheet for beginner chefs in preparing pearl barley.

I would immediately like to put aside talk about the death of a pearl, I do n’t seem to remember somewhere who wrote that if technology has ceased to be fashionable and seems dead, then this means that the technology is mature, its scope is clear and you need to go and work and not pop languages.
I consider Perl 6 as another language and its long and painful birth does not prevent pearl from living and developing.

Of course, it happens that technologies are dying, but if you look at the dates in the history of commits in the pearl repository and the dates in the ribbon for uploading / updating additional modules, you can’t say that the pearl withers - life boils every day. Somehow I specifically monitored modules on CPAN - dozens of modules are updated / uploaded daily.
')
Also note that all free software, and Perl is no exception, is done for Unix-like operating systems, you can do all this on Windows, but you don’t need to, I recommend immediately learning the OS that is normal for the developer (GNU / Linux, FreeBSD).

As usual, everything will be in the crib style, the links will be mainly to the official docks, every dock for a quick start is fully online:

- Newton said that he saw further, because he stood on the shoulders of giants, meaning Galileo and others. Thus, Newton hinted to developers not to write what is already written. And what is already written for a pearl usually lies on the CPAN , you can install it from the repository of your distribution kit (but there is usually not everything there) and with the native utility cpan and its variations cpanp , cpanm (+ useful tool cpan-outdated ). Of course you can write your own, but only if the current implementation is not satisfied with something or you want to understand well how it works.
- Although there is no unanimous opinion about the need for a debugger, there is a debugger in perl -d _ , and it is desirable to have at least minimal control of it: perl -d _
- You can measure the performance of the code using the Benchmark or Dumbbench module , which, according to the author, gives more reliable results.
- You can find bottlenecks using the profiler Devel :: NYTProf , there is a presentation on this topic (there are also modules for finding memory leaks, but I don’t know what’s right now, like Devel :: Leak)
- for unit testing there are Test :: More and mock modules of type Test :: MockObject , well, and a couple of articles: about mock and non-functional tests .
- Minimum perl script / module header
 use strict; use warnings; use utf8; use open (:utf8 :std); use v5.16; #    : perl -v 
There are modules in order to connect everything you need with one line ( Modern :: Perl , uni :: perl , common :: sense ), but they connect a different set of modules - for example, disabling undefined varnings doesn’t work for me, but there is no problem making my own module .
- you need to understand how the pearl works with utf-8 (more precisely, at least to know that everything is not so simple) - dock , article (at the end of the article link to another article)
- it is worth knowing and using good practices and breaking only if you understand why and why, the perlcritic utility can tell where they retreated from the “holy scripture” (I hope I did not offend any believers)
- coding style is a separate topic, you need to take this document as a basis. The perltidy utility perltidy able to bring the coding style to the one described in the configuration = it can be quickly brushed into someone's crookedly formatted code.
- Perl has quite convenient documentation, which can be used without connecting to the network:
 perldoc -f _ perldoc perlre perldoc perlvar  .. 

It is clear that the same thing is in a beautiful form on the network: perldoc , for memorizing all sorts of features such a cheat sheet may be useful, or an extended cheat sheet and spur links , the community can also help, in particular, there is the Moscow Perlovik distribution .
- the creation of modules is described in the documentation , although I think now they are more often done in OOP style, read here and here , if you don’t use heavy modules like Moose, then a competent OOP is use fields and Class :: XSAccessor.
- internationalization, worth reading search.cpan.org/perldoc?Locale :: Maketext :: TPJ13
- documentation - POD
- it is reasonable to design your modules as well as modules for CPAN (it is quite likely that you will fill them there), to simplify this procedure there is a bunch of modules like ExtUtils :: MakeMake and Module :: Starter (there is also Dist :: Zilla , but it is without an installer )
- Exception handling is eval (they have two forms, one with the string argument, this is eval, and the second with the argument code is more than try), there is a good option Try :: Tiny .
- the Carp module provides warn and die analogues with a much more informative output.
- Single lines allow you to quickly do something small, for example, to check if there is a module in the perl -E 'use SOAP::Lite' .
- a complex structure can be displayed in the log / on the screen by the Data :: Dumper module, Data :: Dump is a bit more beautiful + there is also DDP , JSON :: XS is much faster and more suitable for marshaling , but you can also use it for debugging output.
- a good format for YAML configs, module YAML :: XS .
- Sometimes you need to understand which modules the script / module depends on, modules like Module :: ScanDeps can be useful
- the most relevant at the moment web-framework Mojolicious , there is still a Dancer , well, and Catalyst seems to be alive.
- event loops & parallel programming - see comments from vividsnow
- the function parameters can be validated by ready-made modules, for example, Params :: Validate , although it cannot validate complex structures, for this you can use Data :: Validate :: Struct .
- for logging, there are ready-made modules, for example, Log :: Log4perl , Log :: Dispatch and a universal wrapper over various Log :: Any loggers.
- for parsing command line parameters there is a module Getopt :: Long .
- work with DBI and ORM databases of type DBIx :: Class .
- search for the absolute path to the script from the FindBin script and lib :: abs .
- Template and Text :: Xslate template engines , if Mojolicious is used, it is worth using its Mojo :: Template (although you can use it separately).
- Many frequently used functions are in standard modules, for example, for working with lists there is List :: Util and List :: MoreUtils.
- IDE? configure vim, emacs or any other advanced console editor, no monsters needed.
- The base book is “Programming Perl” Larry Wall, Tom Christiansen, Jon Orwant is also a book with a camel, if you want to understand more “Advanced Perl Programming” by Sriram Srinivasan.

About clear names, reasonable size of functions, etc. also need to say, but it is not tied to the pearl and has already been said many times, therefore not here.

Of course, as usual, I expect the help of the collective mind - I’m already tired of remembering what is needed on a large scale, but I don’t want to hit the little things.

UDP: Thanks to people: UncleAndy , Andrey Kovbovich, Pilat , Akzhan Abdulin,
useful comment from afiskon
more from biophreak
and more about the template engine , PSGI , about Test :: More in Russian , source protection , documentation , starting docks .

Source: https://habr.com/ru/post/154613/


All Articles