Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Tomcat42
perl-Perl6-Slurp
perl-Perl6-Slurp.spec
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File perl-Perl6-Slurp.spec of Package perl-Perl6-Slurp
# # spec file for package perl-Perl6-Slurp # # Copyright (c) 2024 SUSE LLC # # 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. # Please submit bugfixes or comments via https://bugs.opensuse.org/ # %define cpan_name Perl6-Slurp Name: perl-Perl6-Slurp Version: 0.51.5 Release: 0 %define cpan_version 0.051005 License: Artistic-1.0 OR GPL-1.0-or-later Summary: Implements the Perl 6 'slurp' built-in URL: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/D/DC/DCONWAY/%{cpan_name}-%{cpan_version}.tar.gz BuildArch: noarch BuildRequires: perl BuildRequires: perl-macros Provides: perl(Perl6::Slurp) = %{version} %undefine __perllib_provides %{perl_requires} %description 'slurp' takes: * a filename, * a filehandle, * a typeglob reference, * an IO::File object, or * a scalar reference, 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. 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. 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. 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 could squeeze single newlines to a single space and multiple consecutive 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 %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 %build perl Makefile.PL INSTALLDIRS=vendor %make_build %check make test %install %perl_make_install %perl_process_packlist %perl_gen_filelist %files -f %{name}.files %doc Changes README %changelog
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor