File Coverage

blib/lib/Data/StreamSerializer.pm
Criterion Covered Total %
statement 51 67 76.1
branch 14 24 58.3
condition 5 9 55.5
subroutine 14 17 82.3
pod 6 6 100.0
total 90 123 73.1


line stmt bran cond sub pod time code
1             package Data::StreamSerializer;
2              
3 5     5   373095 use 5.010001;
  5         23  
  5         259  
4 5     5   30 use strict;
  5         12  
  5         172  
5 5     5   23 use warnings;
  5         14  
  5         251  
6 5     5   26 use Carp;
  5         10  
  5         350  
7              
8 5     5   1568 use Data::Dumper;
  5         21724  
  5         284  
9             require Exporter;
10 5     5   5235 use AutoLoader;
  5         10290  
  5         33  
11              
12             our @ISA = qw(Exporter);
13              
14             # Items to export into callers namespace by default. Note: do not export
15             # names by default without a very good reason. Use EXPORT_OK instead.
16             # Do not simply export all your public functions/methods/constants.
17              
18             # This allows declaration use Data::StreamSerializer ':all';
19             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
20             # will save memory.
21             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
22              
23             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24              
25             our @EXPORT = qw();
26              
27             our $VERSION = '0.07';
28              
29             sub AUTOLOAD {
30             # This AUTOLOAD is used to 'autoload' constants from the constant()
31             # XS function.
32              
33 0     0   0 my $constname;
34 0         0 our $AUTOLOAD;
35 0         0 ($constname = $AUTOLOAD) =~ s/.*:://;
36 0 0       0 croak "&Data::StreamSerializer::constant not defined"
37             if $constname eq 'constant';
38 0         0 my ($error, $val) = constant($constname);
39 0 0       0 if ($error) { croak $error; }
  0         0  
40             {
41 5     5   1125 no strict 'refs';
  5         12  
  5         594  
  0         0  
42 0     0   0 *$AUTOLOAD = sub { $val };
  0         0  
43             }
44 0         0 goto &$AUTOLOAD;
45             }
46              
47             require XSLoader;
48             XSLoader::load('Data::StreamSerializer', $VERSION);
49              
50 5     5   21339 use subs qw(_next);
  5         150  
  5         33  
51             sub new
52             {
53 67     67 1 7191676 my ($class, @data) = @_;
54              
55 67   33     1318 my $self = bless {
56             stack => [ 0 ],
57             data => \@data,
58             eof => 0,
59             recursions => 1,
60             block_size => 512,
61             } => ref($class) || $class;
62              
63 67 100       563 $self->{eof} = 1 unless @data > 0;
64 67         280 return $self;
65             }
66              
67             sub block_size
68             {
69 10210     10210 1 13915 my ($self, $value) = @_;
70 10210 100       50153 return $self->{block_size} unless @_ > 1;
71 1 50       4 croak "block_size must not be zero" unless $value;
72 1         3 return $self->{block_size} = $value;
73             }
74              
75             sub recursion_depth
76             {
77 10210     10210 1 14202 my ($self, $value) = @_;
78 10210 100       1100579 return $self->{recursions} unless @_ > 1;
79 1 50       21 croak "You can't uze zero as recursion_depth parameter"
80             unless $value;
81 1         3 return $self->{recursions} = $value;
82             }
83              
84             sub next
85             {
86 10276     10276 1 63502 my ($self) = @_;
87 10276         17331 local $Data::Dumper::Indent = 0;
88 10276         12344 local $Data::Dumper::Terse = 1;
89 10276         11380 local $Data::Dumper::Useqq = 1;
90 10276         12908 local $Data::Dumper::Deepcopy = 1;
91 10276 100       23312 return if $self->{eof};
92              
93 10209         10437 my $str;
94              
95 10209         22052 my $status = _next($self->{data},
96             $self->block_size,
97             $self->{stack},
98             $self->{eof},
99             \&Dumper,
100             $str,
101             $self->recursion_depth,
102             );
103 10209   66     3795132 $self->{status} ||= $status;
104              
105 10209 100 66     66877 delete $self->{data} if $self->{eof} and exists $self->{data};
106 10209 50       67510 return $str if length $str;
107 0 0       0 return if $self->{eof};
108 0         0 return $str;
109             }
110              
111              
112             sub is_eof
113             {
114 0     0 1 0 my ($self) = @_;
115 0         0 return $self->{eof};
116             }
117              
118             sub recursion_detected
119             {
120 3     3 1 353 my ($self) = @_;
121 3 50       18 return 1 if $self->{status};
122 0         0 return 0;
123             }
124              
125             sub DESTROY
126             {
127 67     67   417790 my ($self) = @_;
128 67         6505 delete $self->{data};
129             }
130              
131              
132             1;
133             __END__