File-chown

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for File-chown

0.02    2015-09-10 (PERLANCAR)

	- No functional changes.

	- [doc] Forgot to write examples in Synopsis.


0.01    2015-09-10 (PERLANCAR)

MANIFEST  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.037.
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
dist.ini
lib/File/chown.pm
t/00-compile.t
t/release-pod-coverage.t
t/release-pod-syntax.t
t/release-rinci.t
weaver.ini

META.json  view on Meta::CPAN

{
   "abstract" : "chown which groks user-/group names and some other extra features",
   "author" : [
      "perlancar <perlancar@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
      "version" : 2
   },
   "name" : "File-chown",
   "prereqs" : {
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "develop" : {
         "requires" : {
            "Pod::Coverage::TrustPod" : "0",
            "Test::Pod" : "1.41",
            "Test::Pod::Coverage" : "1.08",
            "Test::Rinci" : "0.01"
         }
      },
      "runtime" : {
         "recommends" : {
            "File::lchown" : "0"
         },
         "requires" : {
            "perl" : "5.010001"
         }
      },
      "test" : {
         "requires" : {
            "File::Spec" : "0",
            "IO::Handle" : "0",
            "IPC::Open3" : "0",
            "Test::More" : "0"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=File-chown"
      },
      "homepage" : "https://metacpan.org/release/File-chown",
      "repository" : {
         "type" : "git",
         "url" : "git://github.com/perlancar/perl-File-chown.git",
         "web" : "https://github.com/perlancar/perl-File-chown"
      }
   },
   "version" : "0.02",
   "x_Dist_Zilla" : {
      "perl" : {
         "version" : "5.022000"
      },
      "plugins" : [
         {
            "class" : "Dist::Zilla::Plugin::GatherDir",

META.yml  view on Meta::CPAN

---
abstract: 'chown which groks user-/group names and some other extra features'
author:
  - 'perlancar <perlancar@cpan.org>'
build_requires:
  File::Spec: '0'
  IO::Handle: '0'
  IPC::Open3: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: File-chown
recommends:
  File::lchown: '0'
requires:
  perl: '5.010001'
resources:
  bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=File-chown
  homepage: https://metacpan.org/release/File-chown
  repository: git://github.com/perlancar/perl-File-chown.git
version: '0.02'
x_Dist_Zilla:
  perl:
    version: '5.022000'
  plugins:
    -
      class: Dist::Zilla::Plugin::GatherDir
      config:
        Dist::Zilla::Plugin::GatherDir:
          exclude_filename: []

Makefile.PL  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037.
use strict;
use warnings;

use 5.010001;

use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT" => "chown which groks user-/group names and some other extra features",
  "AUTHOR" => "perlancar <perlancar\@cpan.org>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME" => "File-chown",
  "EXE_FILES" => [],
  "LICENSE" => "perl",
  "MIN_PERL_VERSION" => "5.010001",
  "NAME" => "File::chown",
  "PREREQ_PM" => {},
  "TEST_REQUIRES" => {
    "File::Spec" => 0,
    "IO::Handle" => 0,
    "IPC::Open3" => 0,
    "Test::More" => 0
  },
  "VERSION" => "0.02",
  "test" => {
    "TESTS" => "t/*.t"

README  view on Meta::CPAN

SYNOPSIS

     use File::chown; # exports chown() by default
    
     # chown by user-/group names
     chown "ujang", "ujang", @files;
    
     # numeric ID's still work
     chown -1, 500, "myfile.txt";
    
     # option: use a reference file's owner/group instead of specifying directly,
     # like the Unix chown command's --reference=FILE.
     chown({ref => "/etc/passwd"}, "mypasswd");
    
     # option: use lchown instead of chown, like Unix chown command's --no-derefence
     # (-h).
     chown({deref=>0}, "nobody", "nobody", "/home/user/www");

DESCRIPTION

    File::chown provides chown() which overloads the core version with one
    that groks user-/group names, as well as some other extra features.

FUNCTIONS

 chown([ \%opts, ] LIST) => bool

    Changes the owner (and group) of a list of files. Like the core version
    of chown(), The first two elements of the list must be $user and $group
    which can be numeric ID's (or -1 to mean unchanged) or string which
    will be looked up using getpwnam and getgrnam. Function will die if
    lookup fails.

    It accepts an optional first hashref argument containing options. Known
    options:

      * ref => str

      Like --reference option in the chown Unix command, meaning to get
      $user and $group from a specified filename instead of from the first
      two elements of the argument list.

      * deref => bool (default: 1)

      If set to 0 then, like the --no-dereference (-h) option of the chown
      Unix command, will use File::lchown instead of the core chown(). This
      is to set ownership of a symlink itself instead of the symlink
      target.

SEE ALSO

    chown in perlfunc

    The chown Unix command

dist.ini  view on Meta::CPAN

version = 0.02

name    = File-chown

[@Author::PERLANCAR]
:version=0.41

[Prereqs / TestRequires]
;Test::Exception=0
;Test::More=0.98

[Prereqs]
perl=5.010001

[Prereqs / RuntimeRecommends]
;optional
File::lchown=0

lib/File/chown.pm  view on Meta::CPAN

package File::chown;

our $DATE = '2015-09-10'; # DATE
our $VERSION = '0.02'; # VERSION

use 5.010001;
use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
                    chown
            );

sub chown {
    my $opts = ref($_[0]) eq 'HASH' ? shift : {};

    my ($user, $group);
    if ($opts->{ref}) {
        my @st = stat($opts->{ref})
            or die "Can't stat chown ref '$opts->{ref}': $!";
        ($user, $group) = @st[4, 5];
    } else {
        @_ or die "Please specify user";
        $user = shift // -1;
        unless ($user =~ /\A-?\d+\z/) {
            my @pwent = getpwnam($user)
                or die "Unknown user name '$user'";
            $user = $pwent[2];
        }
        @_ or die "Please specify group";
        $group = shift // -1;
        unless ($group =~ /\A-?\d+\z/) {
            my @grent = getgrnam($group)
                or die "Unknown group name '$group'";
            $group = $grent[2];
        }
    }

    if (!($opts->{deref} // 1)) {
        require File::lchown;
        return File::lchown::lchown($user, $group, @_);
    } else {
        return CORE::chown($user, $group, @_);
    }
}

1;
# ABSTRACT: chown which groks user-/group names and some other extra features

__END__

=pod

=encoding UTF-8

=head1 NAME

File::chown - chown which groks user-/group names and some other extra features

=head1 VERSION

This document describes version 0.02 of File::chown (from Perl distribution File-chown), released on 2015-09-10.

=head1 SYNOPSIS

 use File::chown; # exports chown() by default

 # chown by user-/group names
 chown "ujang", "ujang", @files;

 # numeric ID's still work
 chown -1, 500, "myfile.txt";

 # option: use a reference file's owner/group instead of specifying directly,
 # like the Unix chown command's --reference=FILE.
 chown({ref => "/etc/passwd"}, "mypasswd");

 # option: use lchown instead of chown, like Unix chown command's --no-derefence
 # (-h).
 chown({deref=>0}, "nobody", "nobody", "/home/user/www");

=head1 DESCRIPTION

L<File::chown> provides C<chown()> which overloads the core version with one
that groks user-/group names, as well as some other extra features.

=head1 FUNCTIONS

=head2 chown([ \%opts, ] LIST) => bool

Changes the owner (and group) of a list of files. Like the core version of
C<chown()>, The first two elements of the list must be C<$user> and C<$group>
which can be numeric ID's (or -1 to mean unchanged) or string which will be
looked up using C<getpwnam> and C<getgrnam>. Function will die if lookup fails.

It accepts an optional first hashref argument containing options. Known options:

=over

=item * ref => str

Like C<--reference> option in the C<chown> Unix command, meaning to get C<$user>
and C<$group> from a specified filename instead of from the first two elements
of the argument list.

=item * deref => bool (default: 1)

If set to 0 then, like the C<--no-dereference> (C<-h>) option of the C<chown>
Unix command, will use L<File::lchown> instead of the core C<chown()>. This is
to set ownership of a symlink itself instead of the symlink target.

=back

=head1 SEE ALSO

C<chown> in perlfunc

The C<chown> Unix command

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/File-chown>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-File-chown>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=File-chown>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

t/00-compile.t  view on Meta::CPAN

use strict;
use warnings;

# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.053

use Test::More;

plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0);

my @module_files = (
    'File/chown.pm'
);



# no fake home requested

my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib';

use File::Spec;
use IPC::Open3;



( run in 1.049 second using v1.01-cache-2.11-cpan-71847e10f99 )