What a Perl Beginner Must Know About Pearl Infrastructure

    Due to the fact that the shortage of personnel in the IT industry is large, and there are very few pearl barrels (and those that already exist, already want to be tehdirs and get a lot of money), many offices are happy to take capable young people to turn into pearl barley.
    The company in which I now work also thought about this and I remembered my idea to sketch out a certain cheat sheet for beginner chefs for cooking pearl barley.

    I’d like to immediately put aside the talk about the death of the pearl, I do n’t seem to remember somewhere who wrote that if the technology has ceased to be fashionable and seems dead, it means that the technology is mature, its scope is clear and you need to go and work, not crack tongues.
    I consider Perl 6 to be another language, and its long and painful birth does not interfere with the life and development of pearl.

    Of course, it happens that technology dies, but if you look at the dates in the history of commits in the pearl repository and the dates in the fill / update ribbon of additional modules, you can’t say that the pearl is buzzing - life boils daily. Somehow I specifically monitored the modules on CPAN - dozens of modules are updated / poured daily.

    I also note that all free software, and pearl is no exception, is done for Unix-like operating systems, all this can be done on Windows, but it’s not necessary, I recommend immediately mastering a normal operating system for a developer (GNU / Linux, FreeBSD).

    As usual, everything will be in a crib style, the links will be mainly to the official docks, all sorts of docks for a quick start are full on the net:

    - Newton said that he saw further, because he stood on the shoulders of the giants, meaning Galileo and others. Thus, Newton hinted to developers not to write what has already been written. And what has already been written for the pearl usually lies on CPAN , you can install it both from the repository of your distribution (but usually there isn’t everything there), and the native utility cpanand its variations cpanp, cpanm(+ useful tool cpan-outdated). Of course, you can write your own, but only if the current implementations are not happy with something or you want to understand well how it works.
    - And although there is no consensus on the need for a debugger, there is a debugger in the pearl, and it is advisable to at least have a minimal control over it: perl -d имя_скрипта
    - You can measure the code performance using the Benchmark module orDumbbench , which according to the author gives more reliable results.
    - You can find bottlenecks using the Devel :: NYTProf profiler , there is a presentation on this topic (there are also modules for searching for memory leaks, but I don’t know which one is right now, like Devel :: Leak)
    - for unit testing there is Test :: More and mock modules like Test :: MockObject , well, a couple of articles: about mock and non-functional tests .
    - Minimum pearl script / module title
    use strict;
    use warnings;
    use utf8;
    use open (:utf8 :std);
    use v5.16; # тут указать установленную версию: perl -v
    
    There are modules for connecting everything you need in one line ( Modern :: Perl , uni :: perl , common :: sense ), but they connect a different set of modules - for example, disabling undefined warings does not work, but there is no problem making your 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 a link to another article)
    - it is worth knowing and using good practices and breaking only by understanding why and why, the utility perlcriticcan tell where they departed from the "scripture" (I hope not offended any believers)
    - coding style is a separate topic, you need to take this document as a basis . The utility perltidycan bring the coding style to the one described in the configuration = it can be quickly combed by someone's crookedly formatted code.
    - the pearl has a fairly 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 , to remember all sorts of features, such a cheat sheet , or an extended cheat sheet and spur by links , may also help the community , in particular there is a distribution of Moscow barley .
    - the creation of modules is described in the documentation , although I think now they are often made in OOP style, read here and here , if you do not use heavy modules, such as Moose, then competent OOP is use fields and Class :: XSAccessor.
    - internationalization, it is worth reading search.cpan.org/perldoc?Locale:: Maketext :: TPJ13
    - documentation - POD
    - it’s reasonable to format your modules just like the modules for CPAN (it’s likely that you will upload them there), to simplify this procedure there are a bunch of modules like ExtUtils :: MakeMake and Module :: Starter (more there is Dist :: Zilla , but it does not have an installer)
    - Exception handling is eval (they have two forms, one with a line argument is precisely eval, and the second with a code argument is more of a try), there is a good option Try :: Tiny .
    - The Carp module provides analogues of warn and die with significantly more informative output.
    - Single-line allows you to quickly do something small, for example, to check if there is a module in the system perl -E 'use SOAP::Lite'.
    - you can output a complex structure to the log / screen by the module Data :: Dumper , Data :: Dump a little prettier + there is still DDP , JSON :: XS is much faster and more suitable for marshaling , but you can also use it for debug output.
    - A good format for YAML configs , YAML :: XS module .
    - It sometimes happens that you need to understand which modules the script / module depends on, modules like Module :: ScanDeps may be useful
    - the most relevant web-framework Mojolicious at the moment, there’s still Dancer , and Catalyst seems to be alive.
    - event loops & parallel programming - see comment from vividsnow
    - function parameters can be validated with ready-made modules, for example Params :: Validate , although it does not know how to validate complex structures, for this you can use Data :: Validate :: Struct .
    - there are ready-made modules for logging, for example Log :: Log4perl , Log :: Dispatch and a universal wrapper over different Log :: Any loggers .
    - for parsing command line parameters there is a Getopt :: Long module .
    - work with databasesDBI and ORM of type DBIx :: Class .
    - search for the absolute path to the script from the FindBin and lib :: abs script .
    - Template and Text :: Xslate template engines , in case of using Mojolicious it is worth using its Mojo :: Template (although it can be used separately).
    - many commonly used functions are in standard modules, for example, to work with lists, there are List :: Util and List :: MoreUtils.
    - IDE? configure vim, emacs or any other advanced console editor, no monsters needed.
    - the base book is “Programming Perl” by Larry Wall, Tom Christiansen, Jon Orwant she is a book with a camel, if you want to understand more “Advanced Perl Programming” Sriram Srinivasan.

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

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

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

    Also popular now: