| 1 | package IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | ### Stringification, courtesy of B. K. Oxley (binkley): :-) | ||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | use overload '""' => sub { ${*{$_[0]}->{SR}} }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use overload 'bool' => sub { 1 }; ### have to do this, so object is true! | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | ### The package version, both in 1.23 style *and* usable by MakeMaker: | ||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | our $VERSION = '2.113'; | |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||
| 15 | ### Inheritance: | ||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | our @ISA = qw(IO::Handle); | |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||
| 18 | ### This stuff should be got rid of ASAP. | ||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | require IO::WrapTie and push @ISA, 'IO::WrapTie::Slave' if ($] >= 5.004); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$] >= 5.004 && (require IO::WrapTie && push(@IO::Scalar::ISA, 'IO::WrapTie::Slave'))
require IO::WrapTie and push @IO::Scalar::ISA, "IO::WrapTie::Slave"
MC/DC0%0/3
$] >= 5.004 && (require IO::WrapTie && push(@IO::Scalar::ISA, 'IO::WrapTie::Slave'))
$] >= 5.004
require IO::WrapTie
push @IO::Scalar::ISA, "IO::WrapTie::Slave"
Truth table0%0/4
A && B and C
A= $] >= 5.004B= require IO::WrapTieC= push @IO::Scalar::ISA, "IO::WrapTie::Slave"
| |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | #============================== | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||
| 27 | IO::Scalar - IO:: interface for reading/writing a scalar | ||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | Perform I/O on strings, using the basic OO interface... | ||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
| 35 | use IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 36 | $data = "My message:\n"; | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | ### Open a handle on a string, and append to it: | ||||||||||||||||||||||||||||||||||||||||
| 39 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 40 | $SH->print("Hello"); | ||||||||||||||||||||||||||||||||||||||||
| 41 | $SH->print(", world!\nBye now!\n"); | ||||||||||||||||||||||||||||||||||||||||
| 42 | print "The string is now: ", $data, "\n"; | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | ### Open a handle on a string, read it line-by-line, then close it: | ||||||||||||||||||||||||||||||||||||||||
| 45 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 46 | while (defined($_ = $SH->getline)) { | ||||||||||||||||||||||||||||||||||||||||
| 47 | print "Got line: $_"; | ||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||
| 49 | $SH->close; | ||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||
| 51 | ### Open a handle on a string, and slurp in all the lines: | ||||||||||||||||||||||||||||||||||||||||
| 52 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 53 | print "All lines:\n", $SH->getlines; | ||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||
| 55 | ### Get the current position (either of two ways): | ||||||||||||||||||||||||||||||||||||||||
| 56 | $pos = $SH->getpos; | ||||||||||||||||||||||||||||||||||||||||
| 57 | $offset = $SH->tell; | ||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | ### Set the current position (either of two ways): | ||||||||||||||||||||||||||||||||||||||||
| 60 | $SH->setpos($pos); | ||||||||||||||||||||||||||||||||||||||||
| 61 | $SH->seek($offset, 0); | ||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||
| 63 | ### Open an anonymous temporary scalar: | ||||||||||||||||||||||||||||||||||||||||
| 64 | $SH = new IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 65 | $SH->print("Hi there!"); | ||||||||||||||||||||||||||||||||||||||||
| 66 | print "I printed: ", ${$SH->sref}, "\n"; ### get at value | ||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||
| 69 | Don't like OO for your I/O? No problem. | ||||||||||||||||||||||||||||||||||||||||
| 70 | Thanks to the magic of an invisible tie(), the following now | ||||||||||||||||||||||||||||||||||||||||
| 71 | works out of the box, just as it does with IO::Handle: | ||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||
| 73 | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
| 74 | use IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 75 | $data = "My message:\n"; | ||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | ### Open a handle on a string, and append to it: | ||||||||||||||||||||||||||||||||||||||||
| 78 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 79 | print $SH "Hello"; | ||||||||||||||||||||||||||||||||||||||||
| 80 | print $SH ", world!\nBye now!\n"; | ||||||||||||||||||||||||||||||||||||||||
| 81 | print "The string is now: ", $data, "\n"; | ||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||
| 83 | ### Open a handle on a string, read it line-by-line, then close it: | ||||||||||||||||||||||||||||||||||||||||
| 84 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 85 | while (<$SH>) { | ||||||||||||||||||||||||||||||||||||||||
| 86 | print "Got line: $_"; | ||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||
| 88 | close $SH; | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | ### Open a handle on a string, and slurp in all the lines: | ||||||||||||||||||||||||||||||||||||||||
| 91 | $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 92 | print "All lines:\n", <$SH>; | ||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | ### Get the current position (WARNING: requires 5.6): | ||||||||||||||||||||||||||||||||||||||||
| 95 | $offset = tell $SH; | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | ### Set the current position (WARNING: requires 5.6): | ||||||||||||||||||||||||||||||||||||||||
| 98 | seek $SH, $offset, 0; | ||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | ### Open an anonymous temporary scalar: | ||||||||||||||||||||||||||||||||||||||||
| 101 | $SH = new IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 102 | print $SH "Hi there!"; | ||||||||||||||||||||||||||||||||||||||||
| 103 | print "I printed: ", ${$SH->sref}, "\n"; ### get at value | ||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | And for you folks with 1.x code out there: the old tie() style still works, | ||||||||||||||||||||||||||||||||||||||||
| 107 | though this is I<unnecessary and deprecated>: | ||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||
| 109 | use IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||
| 111 | ### Writing to a scalar... | ||||||||||||||||||||||||||||||||||||||||
| 112 | my $s; | ||||||||||||||||||||||||||||||||||||||||
| 113 | tie *OUT, 'IO::Scalar', \$s; | ||||||||||||||||||||||||||||||||||||||||
| 114 | print OUT "line 1\nline 2\n", "line 3\n"; | ||||||||||||||||||||||||||||||||||||||||
| 115 | print "String is now: $s\n" | ||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | ### Reading and writing an anonymous scalar... | ||||||||||||||||||||||||||||||||||||||||
| 118 | tie *OUT, 'IO::Scalar'; | ||||||||||||||||||||||||||||||||||||||||
| 119 | print OUT "line 1\nline 2\n", "line 3\n"; | ||||||||||||||||||||||||||||||||||||||||
| 120 | tied(OUT)->seek(0,0); | ||||||||||||||||||||||||||||||||||||||||
| 121 | while (<OUT>) { | ||||||||||||||||||||||||||||||||||||||||
| 122 | print "Got line: ", $_; | ||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | Stringification works, too! | ||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | my $SH = new IO::Scalar \$data; | ||||||||||||||||||||||||||||||||||||||||
| 129 | print $SH "Hello, "; | ||||||||||||||||||||||||||||||||||||||||
| 130 | print $SH "world!"; | ||||||||||||||||||||||||||||||||||||||||
| 131 | print "I printed: $SH\n"; | ||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||
| 137 | This class is part of the IO::Stringy distribution; | ||||||||||||||||||||||||||||||||||||||||
| 138 | see L<IO::Stringy> for change log and general information. | ||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||
| 140 | The IO::Scalar class implements objects which behave just like | ||||||||||||||||||||||||||||||||||||||||
| 141 | IO::Handle (or FileHandle) objects, except that you may use them | ||||||||||||||||||||||||||||||||||||||||
| 142 | to write to (or read from) scalars. These handles are | ||||||||||||||||||||||||||||||||||||||||
| 143 | automatically C<tiehandle>d (though please see L<"WARNINGS"> | ||||||||||||||||||||||||||||||||||||||||
| 144 | for information relevant to your Perl version). | ||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||
| 147 | Basically, this: | ||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||
| 149 | my $s; | ||||||||||||||||||||||||||||||||||||||||
| 150 | $SH = new IO::Scalar \$s; | ||||||||||||||||||||||||||||||||||||||||
| 151 | $SH->print("Hel", "lo, "); ### OO style | ||||||||||||||||||||||||||||||||||||||||
| 152 | $SH->print("world!\n"); ### ditto | ||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||
| 154 | Or this: | ||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||
| 156 | my $s; | ||||||||||||||||||||||||||||||||||||||||
| 157 | $SH = tie *OUT, 'IO::Scalar', \$s; | ||||||||||||||||||||||||||||||||||||||||
| 158 | print OUT "Hel", "lo, "; ### non-OO style | ||||||||||||||||||||||||||||||||||||||||
| 159 | print OUT "world!\n"; ### ditto | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | Causes $s to be set to: | ||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||
| 163 | "Hello, world!\n" | ||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | =head1 PUBLIC INTERFACE | ||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||
| 168 | =head2 Construction | ||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||
| 170 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||
| 174 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | =item new [ARGS...] | ||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||
| 178 | I<Class method.> | ||||||||||||||||||||||||||||||||||||||||
| 179 | Return a new, unattached scalar handle. | ||||||||||||||||||||||||||||||||||||||||
| 180 | If any arguments are given, they're sent to open(). | ||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||
| 184 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 185 | 12 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||
| 186 | 12 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||
| 187 | 12 | my $self = bless \do { local *FH }, $class; | |||||||||||||||||||||||||||||||||||||||
| 188 | 12 | tie *$self, $class, $self; | |||||||||||||||||||||||||||||||||||||||
| 189 | 12 | $self->open(@_); ### open on anonymous by default | |||||||||||||||||||||||||||||||||||||||
| 190 | 12 | $self; | |||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||
| 192 | 12 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 193 | 12 | shift->close; | |||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||
| 196 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||
| 198 | =item open [SCALARREF] | ||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||
| 200 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 201 | Open the scalar handle on a new scalar, pointed to by SCALARREF. | ||||||||||||||||||||||||||||||||||||||||
| 202 | If no SCALARREF is given, a "private" scalar is created to hold | ||||||||||||||||||||||||||||||||||||||||
| 203 | the file data. | ||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||
| 205 | Returns the self object on success, undefined on error. | ||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | my ($self, $sref) = @_; | |||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||
| 212 | ### Sanity: | ||||||||||||||||||||||||||||||||||||||||
| 213 | 12 | ▶ | defined($sref) or do {my $s = ''; $sref = \$s}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 214 | 12 | ▶ | (ref($sref) eq "SCALAR") or croak "open() needs a ref to a scalar"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||
| 216 | ### Setup: | ||||||||||||||||||||||||||||||||||||||||
| 217 | 12 | *$self->{Pos} = 0; ### seek position | |||||||||||||||||||||||||||||||||||||||
| 218 | 12 | *$self->{SR} = $sref; ### scalar reference | |||||||||||||||||||||||||||||||||||||||
| 219 | 12 | $self; | |||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||
| 222 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||
| 224 | =item opened | ||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||
| 226 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 227 | Is the scalar handle opened on something? | ||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub opened { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
opened: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | *{shift()}->{SR}; | |||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||
| 235 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||
| 237 | =item close | ||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||
| 239 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 240 | Disassociate the scalar handle from its underlying scalar. | ||||||||||||||||||||||||||||||||||||||||
| 241 | Done automatically on destroy. | ||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||
| 245 | 12 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 246 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 247 | 12 | %{*$self} = (); | |||||||||||||||||||||||||||||||||||||||
| 248 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||
| 251 | =back | ||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||
| 257 | #============================== | ||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||
| 259 | =head2 Input and output | ||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||
| 261 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||
| 266 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||
| 268 | =item flush | ||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 271 | No-op, provided for OO compatibility. | ||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||
| 273 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | sub flush { "0 but true" } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||
| 277 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||
| 279 | =item fileno | ||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||
| 281 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 282 | No-op, returns undef | ||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||
| 284 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | ▶ | sub fileno { } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileno: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||
| 288 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||
| 290 | =item getc | ||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||
| 292 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 293 | Return the next character, or undef if none remain. | ||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||
| 295 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||
| 297 | 3 | ▶ | sub getc { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
getc: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||
| 300 | ### Return undef right away if at EOF; else, move pos forward: | ||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | ▶ | return undef if $self->eof; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | substr(${*$self->{SR}}, *$self->{Pos}++, 1); | |||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||
| 305 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||
| 307 | =item getline | ||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||
| 309 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 310 | Return the next line, or undef on end of string. | ||||||||||||||||||||||||||||||||||||||||
| 311 | Can safely be called in an array context. | ||||||||||||||||||||||||||||||||||||||||
| 312 | Currently, lines are delimited by "\n". | ||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||
| 316 | 41 | ▶ | sub getline { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
getline: called CC=13 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 317 | 41 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||
| 319 | ### Return undef right away if at EOF: | ||||||||||||||||||||||||||||||||||||||||
| 320 | 41 | ▶ | return undef if $self->eof; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||
| 322 | ### Get next line: | ||||||||||||||||||||||||||||||||||||||||
| 323 | 35 | my $sr = *$self->{SR}; | |||||||||||||||||||||||||||||||||||||||
| 324 | 35 | my $i = *$self->{Pos}; ### Start matching at this point. | |||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||
| 326 | ### Minimal impact implementation! | ||||||||||||||||||||||||||||||||||||||||
| 327 | ### We do the fast thing (no regexps) if using the | ||||||||||||||||||||||||||||||||||||||||
| 328 | ### classic input record separator. | ||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||
| 330 | ### Case 1: $/ is undef: slurp all... | ||||||||||||||||||||||||||||||||||||||||
| 331 | 35 | ▶ | if (!defined($/)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | *$self->{Pos} = length $$sr; | |||||||||||||||||||||||||||||||||||||||
| 333 | 2 | return substr($$sr, $i); | |||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||
| 336 | ### Case 2: $/ is "\n": zoom zoom zoom... | ||||||||||||||||||||||||||||||||||||||||
| 337 | elsif ($/ eq "\012") { | ||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||
| 339 | ### Seek ahead for "\n"... yes, this really is faster than regexps. | ||||||||||||||||||||||||||||||||||||||||
| 340 | 28 | my $len = length($$sr); | |||||||||||||||||||||||||||||||||||||||
| 341 | 28 | ▶ | for (; $i < $len; ++$i) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 342 | 554 | ▶ | last if ord (substr ($$sr, $i, 1)) == 10; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | ### Extract the line: | ||||||||||||||||||||||||||||||||||||||||
| 346 | 28 | my $line; | |||||||||||||||||||||||||||||||||||||||
| 347 | 28 | ▶ | if ($i < $len) { ### We found a "\n": | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 348 | 25 | $line = substr ($$sr, *$self->{Pos}, $i - *$self->{Pos} + 1); | |||||||||||||||||||||||||||||||||||||||
| 349 | 25 | *$self->{Pos} = $i+1; ### Remember where we finished up. | |||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||
| 351 | else { ### No "\n"; slurp the remainder: | ||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | $line = substr ($$sr, *$self->{Pos}, $i - *$self->{Pos}); | |||||||||||||||||||||||||||||||||||||||
| 353 | 3 | *$self->{Pos} = $len; | |||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||
| 355 | 28 | return $line; | |||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||
| 358 | ### Case 3: $/ is ref to int. Do fixed-size records. | ||||||||||||||||||||||||||||||||||||||||
| 359 | ### (Thanks to Dominique Quatravaux.) | ||||||||||||||||||||||||||||||||||||||||
| 360 | elsif (ref($/)) { | ||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $len = length($$sr); | |||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my $i = ${$/} + 0; | |||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $line = substr ($$sr, *$self->{Pos}, $i); | |||||||||||||||||||||||||||||||||||||||
| 364 | 0 | *$self->{Pos} += $i; | |||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | *$self->{Pos} = $len if (*$self->{Pos} > $len); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return $line; | |||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||
| 369 | ### Case 4: $/ is either "" (paragraphs) or something weird... | ||||||||||||||||||||||||||||||||||||||||
| 370 | ### This is Graham's general-purpose stuff, which might be | ||||||||||||||||||||||||||||||||||||||||
| 371 | ### a tad slower than Case 2 for typical data, because | ||||||||||||||||||||||||||||||||||||||||
| 372 | ### of the regexps. | ||||||||||||||||||||||||||||||||||||||||
| 373 | else { | ||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | pos($$sr) = $i; | |||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||
| 376 | ### If in paragraph mode, skip leading lines (and update i!): | ||||||||||||||||||||||||||||||||||||||||
| 377 | 5 | ▶ | length($/) or | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
length $/ || $$sr =~ /\G\n*/g && ($i = pos $$sr)
$$sr =~ /\G\n*/g and $i = pos $$sr
MC/DC0%0/3
length $/ || $$sr =~ /\G\n*/g && ($i = pos $$sr)
length $/
$$sr =~ /\G\n*/g
$i = pos $$sr
Truth table0%0/4
A || B and C
A= length $/B= $$sr =~ /\G\n*/gC= $i = pos $$sr
| |||||||||||||||||||||||||||||||||||||||||
| 378 | (($$sr =~ m/\G\n*/g) and ($i = pos($$sr))); | ||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||
| 380 | ### If we see the separator in the buffer ahead... | ||||||||||||||||||||||||||||||||||||||||
| 381 | 5 | ▶ | if (length($/) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 382 | ? $$sr =~ m,\Q$/\E,g ### (ordinary sep) TBD: precomp! | ||||||||||||||||||||||||||||||||||||||||
| 383 | : $$sr =~ m,\n\n,g ### (a paragraph) | ||||||||||||||||||||||||||||||||||||||||
| 384 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 385 | 4 | *$self->{Pos} = pos $$sr; | |||||||||||||||||||||||||||||||||||||||
| 386 | 4 | return substr($$sr, $i, *$self->{Pos}-$i); | |||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||
| 388 | ### Else if no separator remains, just slurp the rest: | ||||||||||||||||||||||||||||||||||||||||
| 389 | else { | ||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | *$self->{Pos} = length $$sr; | |||||||||||||||||||||||||||||||||||||||
| 391 | 1 | return substr($$sr, $i); | |||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||
| 396 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||
| 398 | =item getlines | ||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||
| 400 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 401 | Get all remaining lines. | ||||||||||||||||||||||||||||||||||||||||
| 402 | It will croak() if accidentally called in a scalar context. | ||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||
| 404 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | sub getlines { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
getlines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 408 | 2 | ▶ | wantarray or croak("can't call getlines in scalar context!"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | my ($line, @lines); | |||||||||||||||||||||||||||||||||||||||
| 410 | 2 | ▶ | push @lines, $line while (defined($line = $self->getline)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 411 | 2 | @lines; | |||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||
| 414 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||
| 416 | =item print ARGS... | ||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||
| 418 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 419 | Print ARGS to the underlying scalar. | ||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||
| 421 | B<Warning:> this continues to always cause a seek to the end | ||||||||||||||||||||||||||||||||||||||||
| 422 | of the string, but if you perform seek()s and tell()s, it is | ||||||||||||||||||||||||||||||||||||||||
| 423 | still safer to explicitly seek-to-end before subsequent print()s. | ||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||
| 425 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||
| 427 | 12 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 428 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 429 | 12 | ▶ | *$self->{Pos} = length(${*$self->{SR}} .= join('', @_) . (defined($\) ? $\ : "")); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 430 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub _unsafe_print { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unsafe_print: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $append = join('', @_) . $\; | |||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ${*$self->{SR}} .= $append; | |||||||||||||||||||||||||||||||||||||||
| 436 | 0 | *$self->{Pos} += length($append); | |||||||||||||||||||||||||||||||||||||||
| 437 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | sub _old_print { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_old_print: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ${*$self->{SR}} .= join('', @_) . $\; | |||||||||||||||||||||||||||||||||||||||
| 442 | 0 | *$self->{Pos} = length(${*$self->{SR}}); | |||||||||||||||||||||||||||||||||||||||
| 443 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||
| 447 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||
| 449 | =item read BUF, NBYTES, [OFFSET] | ||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||
| 451 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 452 | Read some bytes from the scalar. | ||||||||||||||||||||||||||||||||||||||||
| 453 | Returns the number of bytes actually read, 0 on end-of-file, undef on error. | ||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 458 | 6 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||
| 459 | 6 | my $n = $_[2]; | |||||||||||||||||||||||||||||||||||||||
| 460 | 6 | ▶ | my $off = $_[3] || 0; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[3] || 0
MC/DC0%0/1
$_[3] || 0
$_[3]
Truth table50%1/2
A
A= $_[3]
| |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||
| 462 | 6 | my $read = substr(${*$self->{SR}}, *$self->{Pos}, $n); | |||||||||||||||||||||||||||||||||||||||
| 463 | 6 | $n = length($read); | |||||||||||||||||||||||||||||||||||||||
| 464 | 6 | *$self->{Pos} += $n; | |||||||||||||||||||||||||||||||||||||||
| 465 | 6 | ▶ | ($off ? substr($_[1], $off) : $_[1]) = $read; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 466 | 6 | return $n; | |||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||
| 469 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||
| 471 | =item write BUF, NBYTES, [OFFSET] | ||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||
| 473 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 474 | Write some bytes to the scalar. | ||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||
| 476 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $n = $_[2]; | |||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | my $off = $_[3] || 0; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[3] || 0
MC/DC0%0/1
$_[3] || 0
$_[3]
Truth table0%0/2
A
A= $_[3]
| |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my $data = substr($_[1], $off, $n); | |||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $n = length($data); | |||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->print($data); | |||||||||||||||||||||||||||||||||||||||
| 486 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||
| 489 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||
| 491 | =item sysread BUF, LEN, [OFFSET] | ||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||
| 493 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 494 | Read some bytes from the scalar. | ||||||||||||||||||||||||||||||||||||||||
| 495 | Returns the number of bytes actually read, 0 on end-of-file, undef on error. | ||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||
| 497 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub sysread { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysread: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->read(@_); | |||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||
| 504 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||
| 506 | =item syswrite BUF, NBYTES, [OFFSET] | ||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||
| 508 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 509 | Write some bytes to the scalar. | ||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||
| 511 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | sub syswrite { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
syswrite: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->write(@_); | |||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||
| 518 | =back | ||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||
| 520 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||
| 523 | #============================== | ||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||
| 525 | =head2 Seeking/telling and other attributes | ||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||
| 527 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||
| 529 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||
| 532 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||
| 534 | =item autoflush | ||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||
| 536 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 537 | No-op, provided for OO compatibility. | ||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||
| 539 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | sub autoflush {} | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
autoflush: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||
| 543 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||
| 545 | =item binmode | ||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||
| 547 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 548 | No-op, provided for OO compatibility. | ||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||
| 550 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | sub binmode {} | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
binmode: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||
| 554 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||
| 556 | =item clearerr | ||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||
| 558 | I<Instance method.> Clear the error and EOF flags. A no-op. | ||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | sub clearerr { 1 } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
clearerr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||
| 564 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||
| 566 | =item eof | ||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||
| 568 | I<Instance method.> Are we at end of file? | ||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||
| 570 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||
| 572 | 44 | ▶ | sub eof { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
eof: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 573 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 574 | 44 | (*$self->{Pos} >= length(${*$self->{SR}})); | |||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||
| 577 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||
| 579 | =item seek OFFSET, WHENCE | ||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||
| 581 | I<Instance method.> Seek to a given position in the stream. | ||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||
| 583 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||
| 585 | 11 | ▶ | sub seek { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
seek: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 586 | 11 | my ($self, $pos, $whence) = @_; | |||||||||||||||||||||||||||||||||||||||
| 587 | 11 | my $eofpos = length(${*$self->{SR}}); | |||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||
| 589 | ### Seek: | ||||||||||||||||||||||||||||||||||||||||
| 590 | 11 | ▶ | if ($whence == 0) { *$self->{Pos} = $pos } ### SEEK_SET | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | elsif ($whence == 1) { *$self->{Pos} += $pos } ### SEEK_CUR | |||||||||||||||||||||||||||||||||||||||
| 592 | 1 | elsif ($whence == 2) { *$self->{Pos} = $eofpos + $pos} ### SEEK_END | |||||||||||||||||||||||||||||||||||||||
| 593 | 0 | else { croak "bad seek whence ($whence)" } | |||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||
| 595 | ### Fixup: | ||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | if (*$self->{Pos} < 0) { *$self->{Pos} = 0 } | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | if (*$self->{Pos} > $eofpos) { *$self->{Pos} = $eofpos } | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 598 | 11 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||
| 601 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||
| 603 | =item sysseek OFFSET, WHENCE | ||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||
| 605 | I<Instance method.> Identical to C<seek OFFSET, WHENCE>, I<q.v.> | ||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||
| 607 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub sysseek { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysseek: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $self->seek (@_); | |||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||
| 614 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||
| 616 | =item tell | ||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||
| 618 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 619 | Return the current position in the stream, as a numeric offset. | ||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||
| 621 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | sub tell { *{shift()}->{Pos} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
tell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||
| 625 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 626 | # | ||||||||||||||||||||||||||||||||||||||||
| 627 | # use_RS [YESNO] | ||||||||||||||||||||||||||||||||||||||||
| 628 | # | ||||||||||||||||||||||||||||||||||||||||
| 629 | # I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 630 | # Obey the current setting of $/, like IO::Handle does? | ||||||||||||||||||||||||||||||||||||||||
| 631 | # Default is false in 1.x, but cold-welded true in 2.x and later. | ||||||||||||||||||||||||||||||||||||||||
| 632 | # | ||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | sub use_RS { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
use_RS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | my ($self, $yesno) = @_; | |||||||||||||||||||||||||||||||||||||||
| 635 | 0 | carp "use_RS is deprecated and ignored; \$/ is always consulted\n"; | |||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||
| 638 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||
| 640 | =item setpos POS | ||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||
| 642 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 643 | Set the current position, using the opaque value returned by C<getpos()>. | ||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||
| 645 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | sub setpos { shift->seek($_[0],0) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
setpos: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||
| 649 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||
| 651 | =item getpos | ||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||
| 653 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 654 | Return the current position in the string, as an opaque object. | ||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||
| 656 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||
| 658 | 4 | *getpos = \&tell; | |||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||
| 661 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||
| 663 | =item sref | ||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||
| 665 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||
| 666 | Return a reference to the underlying scalar. | ||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||
| 668 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||
| 670 | 2 | ▶ | sub sref { *{shift()}->{SR} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
sref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||
| 673 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 674 | # Tied handle methods... | ||||||||||||||||||||||||||||||||||||||||
| 675 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||
| 677 | # Conventional tiehandle interface: | ||||||||||||||||||||||||||||||||||||||||
| 678 | 14 | ▶ | sub TIEHANDLE { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 679 | 14 | ▶ | ((defined($_[1]) && UNIVERSAL::isa($_[1], "IO::Scalar")) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_[1] and UNIVERSAL::isa($_[1], "IO::Scalar")
MC/DC100%2/2
defined $_[1] and UNIVERSAL::isa($_[1], "IO::Scalar")
defined $_[1]
UNIVERSAL::isa($_[1], "IO::Scalar")
Truth table100%3/3
A and B
A= defined $_[1]B= UNIVERSAL::isa($_[1], "IO::Scalar")
| |||||||||||||||||||||||||||||||||||||||||
| 680 | ? $_[1] | ||||||||||||||||||||||||||||||||||||||||
| 681 | : shift->new(@_)); | ||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | sub GETC { shift->getc(@_) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
GETC: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 684 | 9 | ▶ | sub PRINT { shift->print(@_) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
PRINT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | sub PRINTF { shift->print(sprintf(shift, @_)) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
PRINTF: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | sub READ { shift->read(@_) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
READ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 687 | 8 | ▶ | sub READLINE { wantarray ? shift->getlines(@_) : shift->getline(@_) } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
READLINE: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | sub WRITE { shift->write(@_); } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
WRITE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | sub CLOSE { shift->close(@_); } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLOSE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | sub SEEK { shift->seek(@_); } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
SEEK: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | sub TELL { shift->tell(@_); } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
TELL: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | sub EOF { shift->eof(@_); } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
EOF: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | sub BINMODE { 1; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BINMODE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||
| 695 | #------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||
| 697 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||
| 699 | __END__ | ||||||||||||||||||||||||||||||||||||||||