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