File: Printers.pm

package info (click to toggle)
libdata-dump-streamer-perl 2.42-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 828 kB
  • sloc: perl: 3,206; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
    package    # hide from PAUSE
        Data::Dump::Streamer::_::StringPrinter;
    $VERSION= "0.1";
    my %items;
    sub DESTROY { delete $items{ $_[0] } }

    sub new {
        my $class= shift;
        my $self= bless \do { my $str= '' }, $class;
        $self->print(@_);
        return $self;
    }

    sub print {
        my $self= shift;
        $items{$self} .= join "", @_;
    }
    sub value  { $items{ $_[0] } }
    sub string { $_[0]->value() }
    1;
}

{

    package    # Hide from PAUSE
        Data::Dump::Streamer::_::ListPrinter;
    $VERSION= "0.1";
    my %items;
    sub DESTROY { delete $items{ $_[0] } }

    sub new {
        my $class= shift;
        my $self= bless \do { my $str= '' }, $class;
        $items{$self}= [];
        $self->print(@_);
        return $self;
    }

    sub print {
        my $self= $items{ shift(@_) };
        my $str= join('', @_);
        if (  !@$self
            or $self->[-1] =~ /\n/
            or length($self->[-1]) > 4000)
        {
            push @{$self}, $str;
        }
        else {
            $self->[-1] .= $str;
        }
    }
    sub value  { @{ $items{ $_[0] } } }
    sub string { join('', @{ $items{ $_[0] } }) }
    1;
}

__END__