2012-05-08 08:38:14 +00:00
|
|
|
#
|
|
|
|
# spec file for package perl-Perl6-Slurp
|
|
|
|
#
|
2024-03-12 17:18:26 +00:00
|
|
|
# Copyright (c) 2024 SUSE LLC
|
2012-05-08 08:38:14 +00:00
|
|
|
#
|
|
|
|
# All modifications and additions to the file contributed by third parties
|
|
|
|
# remain the property of their copyright owners, unless otherwise agreed
|
|
|
|
# upon. The license for this file, and modifications and additions to the
|
|
|
|
# file, is the same license as for the pristine package itself (unless the
|
|
|
|
# license for the pristine package is not an Open Source License, in which
|
|
|
|
# case the license is the MIT License). An "Open Source License" is a
|
|
|
|
# license that conforms to the Open Source Definition (Version 1.9)
|
|
|
|
# published by the Open Source Initiative.
|
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
2012-05-08 08:38:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
%define cpan_name Perl6-Slurp
|
2012-05-08 08:38:14 +00:00
|
|
|
Name: perl-Perl6-Slurp
|
2024-03-12 17:18:26 +00:00
|
|
|
Version: 0.51.5
|
2012-05-08 08:38:14 +00:00
|
|
|
Release: 0
|
2024-03-12 17:18:26 +00:00
|
|
|
%define cpan_version 0.051005
|
|
|
|
License: Artistic-1.0 OR GPL-1.0-or-later
|
2012-05-08 08:38:14 +00:00
|
|
|
Summary: Implements the Perl 6 'slurp' built-in
|
2024-03-12 17:18:26 +00:00
|
|
|
URL: https://metacpan.org/release/%{cpan_name}
|
|
|
|
Source0: https://cpan.metacpan.org/authors/id/D/DC/DCONWAY/%{cpan_name}-%{cpan_version}.tar.gz
|
2025-08-12 18:16:26 +02:00
|
|
|
Source100: README.md
|
2012-05-08 08:38:14 +00:00
|
|
|
BuildArch: noarch
|
|
|
|
BuildRequires: perl
|
|
|
|
BuildRequires: perl-macros
|
2024-03-12 17:18:26 +00:00
|
|
|
Provides: perl(Perl6::Slurp) = %{version}
|
|
|
|
%undefine __perllib_provides
|
2012-05-08 08:38:14 +00:00
|
|
|
%{perl_requires}
|
|
|
|
|
|
|
|
%description
|
|
|
|
'slurp' takes:
|
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
* a filename,
|
2012-05-08 08:38:14 +00:00
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
* a filehandle,
|
2012-05-08 08:38:14 +00:00
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
* a typeglob reference,
|
2012-05-08 08:38:14 +00:00
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
* an IO::File object, or
|
2012-05-08 08:38:14 +00:00
|
|
|
|
2024-03-12 17:18:26 +00:00
|
|
|
* a scalar reference,
|
2012-05-08 08:38:14 +00:00
|
|
|
|
2015-04-14 05:39:45 +00:00
|
|
|
converts it to an input stream (using 'open()' if necessary), and reads in
|
|
|
|
the entire stream. If 'slurp' fails to set up or read the stream, it throws
|
|
|
|
an exception.
|
2012-05-08 08:38:14 +00:00
|
|
|
|
|
|
|
If no data source is specified 'slurp' uses the value of '$_' as the
|
|
|
|
source. If '$_' is undefined, 'slurp' uses the '@ARGV' list, and magically
|
|
|
|
slurps the contents of _all_ the sources listed in '@ARGV'. Note that the
|
|
|
|
same magic is also applied if you explicitly slurp <*ARGV>, so the
|
|
|
|
following three input operations:
|
|
|
|
|
|
|
|
$contents = join "", <ARGV>;
|
|
|
|
|
|
|
|
$contents = slurp \*ARGV;
|
|
|
|
|
|
|
|
$/ = undef;
|
|
|
|
$contents = slurp;
|
|
|
|
|
|
|
|
are identical in effect.
|
|
|
|
|
|
|
|
In a scalar context 'slurp' returns the stream contents as a single string.
|
|
|
|
If the stream is at EOF, it returns an empty string. In a list context, it
|
|
|
|
splits the contents after the appropriate input record separator and
|
|
|
|
returns the resulting list of strings.
|
|
|
|
|
|
|
|
You can set the input record separator ('{ irs => $your_irs_here}') for the
|
|
|
|
input operation. The separator can be specified as a string or a regex.
|
2015-04-14 05:39:45 +00:00
|
|
|
Note that an explicit input record separator has no input-terminating
|
|
|
|
effect in a scalar context; 'slurp' always reads in the entire input
|
|
|
|
stream, whatever the ''irs'' value.
|
2012-05-08 08:38:14 +00:00
|
|
|
|
|
|
|
In a list context, changing the separator can change how the input is
|
|
|
|
broken up within the list that is returned.
|
|
|
|
|
|
|
|
If an input record separator is not explicitly specified, 'slurp' defaults
|
|
|
|
to '"\n"' (_not_ to the current value of '$/' ndash since Perl 6 doesn't
|
|
|
|
_have_ a '$/');
|
|
|
|
|
|
|
|
You can also tell 'slurp' to automagically 'chomp' the input as it is read
|
|
|
|
in, by specifying: ('{ chomp => 1 }')
|
|
|
|
|
|
|
|
Better still, you can tell 'slurp' to automagically 'chomp' the input and
|
|
|
|
_replace_ what it chomps with another string, by specifying: ('{ chomp =>
|
|
|
|
"another string" }')
|
|
|
|
|
|
|
|
You can also tell 'slurp' to compute the replacement string on-the-fly by
|
|
|
|
specifying a subroutine as the 'chomp' value: ('{ chomp => sub{...} }').
|
|
|
|
This subroutine is passed the string being chomped off, so for example you
|
2015-04-14 05:39:45 +00:00
|
|
|
could squeeze single newlines to a single space and multiple consecutive
|
2012-05-08 08:38:14 +00:00
|
|
|
newlines to a two newlines with:
|
|
|
|
|
|
|
|
sub squeeze {
|
|
|
|
my ($removed) = @_;
|
|
|
|
if ($removed =~ tr/\n/\n/ == 1) { return " " }
|
|
|
|
else { return "\n\n"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
print slurp(\*DATA, {irs=>qr/[ \t]*\n+/, chomp=>\&squeeze}), "\n";
|
|
|
|
|
|
|
|
Which would transform:
|
|
|
|
|
|
|
|
This is the
|
|
|
|
first paragraph
|
|
|
|
|
|
|
|
|
|
|
|
This is the
|
|
|
|
second
|
|
|
|
paragraph
|
|
|
|
|
|
|
|
This, the
|
|
|
|
third
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This one is
|
|
|
|
the
|
|
|
|
very
|
|
|
|
last
|
|
|
|
|
|
|
|
to:
|
|
|
|
|
|
|
|
This is the first paragraph
|
|
|
|
|
|
|
|
This is the second paragraph
|
|
|
|
|
|
|
|
This, the third
|
|
|
|
|
|
|
|
This one is the very last
|
|
|
|
|
|
|
|
Autochomping works in both scalar and list contexts. In scalar contexts
|
|
|
|
every instance of the input record separator will be removed (or replaced)
|
|
|
|
within the returned string. In list context, each list item returned with
|
|
|
|
its terminating separator removed (or replaced).
|
|
|
|
|
|
|
|
You can specify I/O layers, either using the Perl 5 notation:
|
|
|
|
|
|
|
|
slurp "<:layer1 :layer2 :etc", $filename;
|
|
|
|
|
|
|
|
or as an array of options:
|
|
|
|
|
|
|
|
slurp $filename, [layer1=>1, layer2=>1, etc=>1];
|
|
|
|
slurp [layer1=>1, layer2=>1, etc=>1], $filename;
|
|
|
|
|
|
|
|
or as individual options (each of which must be in a separate hash):
|
|
|
|
|
|
|
|
slurp $filename, {layer1=>1}, {layer2=>1}, {etc=>1};
|
|
|
|
slurp {layer1=>1}, {layer2=>1}, {etc=>1}, $filename;
|
|
|
|
|
|
|
|
(...which, of course, would look much cooler in Perl 6:
|
|
|
|
|
|
|
|
# Perl 6 only :-(
|
|
|
|
|
|
|
|
slurp $filename, :layer1 :layer2 :etc;
|
|
|
|
slurp :layer1 :layer2 :etc, $filename;
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
A common mistake is to put all the options together in one hash:
|
|
|
|
|
|
|
|
slurp $filename, {layer1=>1, layer2=>1, etc=>1};
|
|
|
|
|
|
|
|
This is almost always a disaster, since the order of I/O layers is usually
|
|
|
|
critical, and placing them all in one hash effectively randomizes that
|
|
|
|
order. Use an array instead:
|
|
|
|
|
|
|
|
slurp $filename, [layer1=>1, layer2=>1, etc=>1];
|
|
|
|
|
|
|
|
%prep
|
2024-03-12 17:18:26 +00:00
|
|
|
%autosetup -n %{cpan_name}-%{cpan_version}
|
|
|
|
|
|
|
|
find . -type f ! -path "*/t/*" ! -name "*.pl" ! -path "*/bin/*" ! -path "*/script/*" ! -path "*/scripts/*" ! -name "configure" -print0 | xargs -0 chmod 644
|
2012-05-08 08:38:14 +00:00
|
|
|
|
|
|
|
%build
|
2024-03-12 17:18:26 +00:00
|
|
|
perl Makefile.PL INSTALLDIRS=vendor
|
|
|
|
%make_build
|
2012-05-08 08:38:14 +00:00
|
|
|
|
|
|
|
%check
|
2024-03-12 17:18:26 +00:00
|
|
|
make test
|
2012-05-08 08:38:14 +00:00
|
|
|
|
|
|
|
%install
|
|
|
|
%perl_make_install
|
|
|
|
%perl_process_packlist
|
|
|
|
%perl_gen_filelist
|
|
|
|
|
|
|
|
%files -f %{name}.files
|
|
|
|
%doc Changes README
|
|
|
|
|
|
|
|
%changelog
|