Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: shedding a bash wrapper and updating to Path::Tiny

by kevbot (Priest)
on Jul 07, 2018 at 02:31 UTC ( #1218076=note: print w/replies, xml ) Need Help??

in reply to shedding a bash wrapper and updating to Path::Tiny

Hello Datz_cozee75,

Here is a gentle introduction to Path::Tiny: Path::Tiny: The little module that keeps on giving. After you finish up with that, then I recommend you take a closer look at the documentation for Path::Tiny. For example, some Path::Tiny methods that may be relevant to your script are children, chmod, copy, exists, is_file, is_dir, mkpath, slurp, and stringify. Also, for changing file permissions/owners take a look at the documentation for chown. I think you will be more likely to receive constructive feedback if you attempt to modify your script and post the results in this thread.

  • Comment on Re: shedding a bash wrapper and updating to Path::Tiny

Replies are listed 'Best First'.
Re^2: shedding a bash wrapper and updating to Path::Tiny
by Aldebaran (Curate) on Jul 10, 2018 at 22:54 UTC

    Thank you for your reply, and I understand that it's hard to comment on code that has yet to be shown. I appreciated the remarks before I start into these: they give me goals to work towards. I've done about half of the changeover to Path::Tiny for this workspace, and I've been really pleased with results so far. I've chopped out many lines and even one entire routine. It would be very pleasing if I could wrest this software tool completely from bash. Where it starts is last html page with utf8 captions, showing a successful cloning of the last stable upgrade.

    Alright, so on all of the files copied, if they match either "pl" or "sh", then I want them set to 0755. Should I set directories containing these scripts to 0755 as well?

    Page for perlmonks shows progress with changing the path on the server directory. I've started to attack the clone script from the top, clearing out the modules I'm not gonna use anymore. For this task, I might only need Path::Tiny, but need to get some feeling as to how it works. Where I'm hung up now is with the logic from switching over from File::Copy. I've commented out what used to work:

    Where I can't follow the logic is the analog of the copy command. Terminal output is:

    $ ./ ------------- making directories ------------- copying files matching is 5.unicode1.css copy failed for /home/bob/1.scripts/pages/ +de1.css to 1/5.unicode1.css: No such file or directory at ./4.clone.p +l line 41. $

    Thanks all for comments, and I *do read* what people post for me. Please understand, I'm a pilgrim who is overachieving to become a friar, so the more-complicated method calls in Path::Tiny are a bit tough for me. I think the investment in figuring it out and switching over is gonna be time well spent.

      I finally got it to work. It's hugely verbose, so I'll put output in readmore tags. I just kept on trying things until something worked. Path::Tiny examples are in the middle of this script. I worked the examples of Path::Class given on a path class page on perladvert. Now I'm gonna start editing, making it less verbose.

      The script is still in transition, and the produced html page has the code from the $from directory and the content from the $pop directory: new html page with new content . This is what exists now. The %vars is not hooked up to anything yet in this script.

      I found that I had to stringify more than I was anticipating but could not stringify for ( $abs_pop->children ) {}. By the end, I figured out that I could use chdir and Path::Tiny to bring me where I needed to be instead of creating some ginormous path. It seems to work fine without quotes. (tested only once)

      How do I change the logic so that .tmpl files don't get set to execute because they end in pl?

      Accepting any criticisms of style. Does one use quotes in the path calls all the times or just sometimes?

        Hello Datz_cozee75,

        Here are a few comments.

        • Path::Tiny has a method for getting the absolute path of the current working directory, so path(".")->absolute; with  Path::Tiny->cwd;
        • You do not need to quote the variables when you create a new path, so code like this path( "$current", "$to", "$ts" ) can be changed to code like this path( $current, $to, $ts )
        • You do not need to use stringify on a path before printing it, so code like this say "string abs from is $string_abs_from"; can be changed to use the variable that contains the Path::Tiny object like this say "string abs from is $abs_from";. Generally, Path::Tiny objects will stringify on their own when necessary. However, there may be times when you are passing a Path::Tiny object to another method (for example, a method from a different CPAN package) you may sometimes need to stringify the path first.
        • I like to use named variables in my foreach loops, so I made some changes to reflect this.
        • The Path::Tiny children method can be given an argument of a regular expression, where only children that match the regular expression are returned. This allowed me to simplify your code a bit.

        Here is the modified code. Please note that this code is untested and I did this quickly, so it may need some small adjustments and there may be some typos. Please be sure that you have a backup of your data before running this code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218076]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2022-09-28 22:26 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.