| 1 | package XAS::Lib::Mixins::Bufops; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.01'; | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Params::Validate qw(SCALAR SCALARREF); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | use XAS::Class | ||||||||||
| 7 | 1 | debug => 0, | |||||||||
| 8 | version => $VERSION, | ||||||||||
| 9 | base => 'XAS::Base', | ||||||||||
| 10 | mixins => 'buf_slurp buf_get_line' | ||||||||||
| 11 | 1 | ▶ | ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | # ---------------------------------------------------------------------- | ||||||||||
| 14 | # Public Methods | ||||||||||
| 15 | # ---------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | sub buf_slurp { | ||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
buf_slurp: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 19 | 0 | my ($buffer, $pos) = $self->validate_params(\@_, [ | |||||||||
| 20 | { type => SCALARREF }, | ||||||||||
| 21 | { type => SCALAR }, | ||||||||||
| 22 | ]); | ||||||||||
| 23 | |||||||||||
| 24 | 0 | my $output; | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | if ($output = substr($$buffer, 0, $pos)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | substr($$buffer, 0, $pos) = ''; | |||||||||
| 29 | |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | return $output; | |||||||||
| 33 | |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub buf_get_line { | ||||||||||
| 37 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
buf_get_line: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 38 | 0 | my ($buffer, $eol) = $self->validate_params(\@_, [ | |||||||||
| 39 | { type => SCALARREF }, | ||||||||||
| 40 | { type => SCALAR | SCALARREF }, | ||||||||||
| 41 | ]); | ||||||||||
| 42 | |||||||||||
| 43 | 0 | my $pos; | |||||||||
| 44 | my $output; | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | if ($$buffer =~ m/$eol/g) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | $pos = pos($$buffer); | |||||||||
| 49 | 0 | $output = $self->buf_slurp($buffer, $pos); | |||||||||
| 50 | |||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | return $output; | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | # ---------------------------------------------------------------------- | ||||||||||
| 58 | # Private Methods | ||||||||||
| 59 | # ---------------------------------------------------------------------- | ||||||||||
| 60 | |||||||||||
| 61 | 1 | 1; | |||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||
| 64 | |||||||||||
| 65 | =head1 NAME | ||||||||||
| 66 | |||||||||||
| 67 | XAS::Lib::Mixins::Bufops - A class for the XAS environment | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | use XAS::Class | ||||||||||
| 72 | debug => 0, | ||||||||||
| 73 | version => '0.01', | ||||||||||
| 74 | base => 'XAS::Base', | ||||||||||
| 75 | mixin => 'XAS::Lib::Mixins::Bufops', | ||||||||||
| 76 | ; | ||||||||||
| 77 | |||||||||||
| 78 | my $buffer = "this is a buffer", | ||||||||||
| 79 | |||||||||||
| 80 | my $word = $self->buf_get_line(\$buffer, ' '); | ||||||||||
| 81 | |||||||||||
| 82 | =head1 DESCRIPTION | ||||||||||
| 83 | |||||||||||
| 84 | This module performs some common operations on buffers. | ||||||||||
| 85 | |||||||||||
| 86 | =head1 METHODS | ||||||||||
| 87 | |||||||||||
| 88 | =head2 buf_get_line(\$buffer, $eol) | ||||||||||
| 89 | |||||||||||
| 90 | This method returns a "line" from a buffer. | ||||||||||
| 91 | |||||||||||
| 92 | =over 4 | ||||||||||
| 93 | |||||||||||
| 94 | =item B<$buffer> | ||||||||||
| 95 | |||||||||||
| 96 | A pointer to a buffer. | ||||||||||
| 97 | |||||||||||
| 98 | =item B<$eol> | ||||||||||
| 99 | |||||||||||
| 100 | A delimiter to search for. This denotes the end of the line. | ||||||||||
| 101 | |||||||||||
| 102 | =back | ||||||||||
| 103 | |||||||||||
| 104 | =head2 buf_slurp(\$buffer, $length) | ||||||||||
| 105 | |||||||||||
| 106 | This method will extract a chunk from the buffer. The buffer will shrink | ||||||||||
| 107 | by that amount. | ||||||||||
| 108 | |||||||||||
| 109 | =over 4 | ||||||||||
| 110 | |||||||||||
| 111 | =item B<$buffer> | ||||||||||
| 112 | |||||||||||
| 113 | A pointer to a buffer. | ||||||||||
| 114 | |||||||||||
| 115 | =item B<$length> | ||||||||||
| 116 | |||||||||||
| 117 | The length of the chunk. | ||||||||||
| 118 | |||||||||||
| 119 | =back | ||||||||||
| 120 | |||||||||||
| 121 | =head1 SEE ALSO | ||||||||||
| 122 | |||||||||||
| 123 | =over 4 | ||||||||||
| 124 | |||||||||||
| 125 | =item L<XAS|XAS> | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =head1 AUTHOR | ||||||||||
| 130 | |||||||||||
| 131 | Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> | ||||||||||
| 132 | |||||||||||
| 133 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 134 | |||||||||||
| 135 | Copyright (C) 2014 Kevin L. Esteb | ||||||||||
| 136 | |||||||||||
| 137 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 138 | the terms of the Artistic License 2.0. For details, see the full text | ||||||||||
| 139 | of the license at http://www.perlfoundation.org/artistic_license_2_0. | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||