Aion-Fs

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

path +{ ext => joinext qw/x y z/ } # => .x.y.z
```

## include (;$pkg)

Подключает `$pkg` (если он ещё не был подключён через `use` или `require`) и возвращает его. Без параметра использует `$_`.

Файл lib/A.pm:
```perl
package A;
sub new { bless {@_}, shift }
1;
```

Файл lib/N.pm:
```perl
package N;
sub ex { 123 }
1;
```

lib/Aion/Fs.md  view on Meta::CPAN

path +{ ext => joinext qw/x y z/ } # => .x.y.z
```

## include (;$pkg)

Подключает `$pkg` (если он ещё не был подключён через `use` или `require`) и возвращает его. Без параметра использует `$_`.

Файл lib/A.pm:
```perl
package A;
sub new { bless {@_}, shift }
1;
```

Файл lib/N.pm:
```perl
package N;
sub ex { 123 }
1;
```

lib/Aion/Fs.pm  view on Meta::CPAN

	my $files = @_? shift: $_;
    $files = [$files] unless ref $files;

	my @noenters; my $errorenter = sub {};
	
	my $ex = @_ && ref($_[$#_]) eq 'Aion::Fs::Find'
		? pop
		: undef;

	if($ex) {
		bless $ex, 'Aion::Fs';
		if(Scalar::Util::reftype $ex eq 'CODE') {
			$errorenter = $ex;
		} else {
			$errorenter = bless pop @$ex, undef if Scalar::Util::reftype($ex->[$#$ex]) eq "CODE";
			push @noenters, _filters @$ex;
		}
	}
	
	my @filters = _filters @_;

	my $iter = Aion::Fs::Find->new(
		noenters => \@noenters,
		errorenter => $errorenter,
		filters => \@filters,
		files => $files,
	);

	defined(wantarray)
		? (wantarray? @$iter: $iter)
		: do { while(defined $iter->next) {} };
}

# Не входить в подкаталоги
sub noenter(@) {
	bless [@_], "Aion::Fs::Find"
}

# Вызывается для всех ошибок ввода-вывода
sub errorenter(&) {
	bless shift, "Aion::Fs::Find"
}

# Останавливает find будучи вызван с одного из его фильтров, errorenter или noenter
sub find_stop() {
	die bless \(my $stop = 1), "Aion::Fs::Find"
}

# Производит замену во всех указанных файлах. Возвращает файлы в которых замен не было
sub replace(&@) {
    my $fn = shift;
	my @noreplace; local $_; my $pkg = caller;
	my $aref = "$pkg\::a";	my $bref = "$pkg\::b";
    for $$aref (@_) {
		if(ref $$aref) { ($$aref, $$bref) = @$$aref } else { $$bref = ":utf8" }
        my $file = $_ = cat [$$aref, $$bref];

lib/Aion/Fs.pm  view on Meta::CPAN

	
	path +{ ext => joinext qw/x y z/ } # => .x.y.z

=head2 include (;$pkg)

Connects C<$pkg> (if it has not already been connected via C<use> or C<require>) and returns it. Without a parameter, uses C<$_>.

lib/A.pm file:

	package A;
	sub new { bless {@_}, shift }
	1;

lib/N.pm file:

	package N;
	sub ex { 123 }
	1;



lib/Aion/Fs/Cat.pm  view on Meta::CPAN

	'&{}' => sub {
		my ($self) = @_;
		sub { scalar $self->next }
	},
	'@{}' => sub { [shift->next] },
	'""' => sub { "cat<${\shift->{path}}>" },
;

sub new {
	my $cls = shift;
	bless {@_}, ref $cls || $cls
}

sub path { shift->{path} }

sub next {
	my $f = shift->{f};
	<$f>
}

sub DESTROY {

lib/Aion/Fs/Find.pm  view on Meta::CPAN

	'@{}' => sub {
		my ($self) = @_;
		my @paths; my $path;
		push @paths, $path while defined($path = $self->next);
		\@paths
	},
;

sub new {
	my $cls = shift;
	bless {@_}, ref $cls || $cls
}

sub next {
	my ($self) = @_;
	my $path = eval {
		my $files = $self->{files};
	    FILE: while(@$files) {
			my $path = shift @$files;

			if(-d $path) {

lib/Aion/Fs/Lay.pm  view on Meta::CPAN

use common::sense;

use overload fallback => 1,
	'*{}' => sub { shift->{f} },
	'-X' => \&_fileop,
	'""' => sub { "lay<${\shift->{path}}>" },
;

sub new {
	my $cls = shift;
	bless {@_}, ref $cls || $cls
}

sub path { shift->{path} }

sub DESTROY {
	my ($self) = @_;

	close $self->{f};
}

t/aion/fs.t  view on Meta::CPAN

local ($::_g0 = do {path +{ ext => joinext qw/x y z/ }}, $::_e0 = ".x.y.z"); ::ok $::_g0 eq $::_e0, 'path +{ ext => joinext qw/x y z/ } # => .x.y.z' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

# 
# ## include (;$pkg)
# 
# Подключает `$pkg` (если он ещё не был подключён через `use` или `require`) и возвращает его. Без параметра использует `$_`.
# 
# Файл lib/A.pm:
#@> lib/A.pm
#>> package A;
#>> sub new { bless {@_}, shift }
#>> 1;
#@< EOF
# 
# Файл lib/N.pm:
#@> lib/N.pm
#>> package N;
#>> sub ex { 123 }
#>> 1;
#@< EOF
# 



( run in 2.718 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )