File Coverage

blib/lib/Archive/Har/Entry/Response/Content.pm
Criterion Covered Total %
statement 9 90 10.0
branch 0 44 0.0
condition n/a
subroutine 3 12 25.0
pod 7 8 87.5
total 19 154 12.3


line stmt bran cond sub pod time code
1             package Archive::Har::Entry::Response::Content;
2              
3 1     1   5 use warnings;
  1         2  
  1         28  
4 1     1   5 use strict;
  1         2  
  1         24  
5 1     1   5 use Carp();
  1         2  
  1         1008  
6              
7             our $VERSION = 0.19;
8              
9             sub new {
10 0     0 1   my ( $class, $params ) = @_;
11 0           my $self = {};
12 0           bless $self, $class;
13 0 0         if ( defined $params ) {
14 0           $self->size( $params->{size} );
15 0           $self->mime_type( $params->{mimeType} );
16 0 0         if ( defined $params->{compression} ) {
17 0           $self->compression( $params->{compression} );
18             }
19 0 0         if ( defined $params->{text} ) {
20 0           $self->text( $params->{text} );
21             }
22 0 0         if ( defined $params->{encoding} ) {
23 0           $self->encoding( $params->{encoding} );
24             }
25 0 0         if ( defined $params->{comment} ) {
26 0           $self->comment( $params->{comment} );
27             }
28 0           foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
  0            
  0            
29 0 0         if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
30 0           $self->$key( $params->{$key} );
31             }
32             }
33             }
34 0           return $self;
35             }
36              
37             sub mime_type {
38 0     0 1   my ( $self, $new ) = @_;
39 0           my $old = $self->{mimeType};
40 0 0         if ( @_ > 1 ) {
41 0           $self->{mimeType} = $new;
42             }
43 0 0         if ( defined $old ) {
44 0           return $old;
45             }
46             else {
47 0           return 'text/plain';
48             }
49             }
50              
51             sub size {
52 0     0 1   my ( $self, $new ) = @_;
53 0           my $old = $self->{size};
54 0 0         if ( @_ > 1 ) {
55 0           $self->{size} = $new;
56             }
57 0 0         if ( defined $old ) {
58 0           return $old;
59             }
60             else {
61 0           return 0;
62             }
63             }
64              
65             sub compression {
66 0     0 1   my ( $self, $new ) = @_;
67 0           my $old = $self->{compression};
68 0 0         if ( @_ > 1 ) {
69 0           $self->{compression} = $new;
70             }
71 0           return $old;
72             }
73              
74             sub text {
75 0     0 1   my ( $self, $new ) = @_;
76 0           my $old = $self->{text};
77 0 0         if ( @_ > 1 ) {
78 0           $self->{text} = $new;
79             }
80 0           return $old;
81             }
82              
83             sub encoding {
84 0     0 1   my ( $self, $new ) = @_;
85 0           my $old = $self->{encoding};
86 0 0         if ( @_ > 1 ) {
87 0           $self->{encoding} = $new;
88             }
89 0           return $old;
90             }
91              
92             sub comment {
93 0     0 1   my ( $self, $new ) = @_;
94 0           my $old = $self->{comment};
95 0 0         if ( @_ > 1 ) {
96 0           $self->{comment} = $new;
97             }
98 0           return $old;
99             }
100              
101             sub AUTOLOAD {
102 0     0     my ( $self, $new ) = @_;
103              
104 0           my $name = $Archive::Har::Entry::Response::Content::AUTOLOAD;
105 0           $name =~ s/.*://smx; # strip fully-qualified portion
106              
107 0           my $old;
108 0 0         if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
109 0           $old = $self->{$name};
110 0 0         if ( @_ > 1 ) {
111 0           $self->{$name} = $new;
112             }
113             }
114             else {
115 0           Carp::croak(
116             "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
117             );
118             }
119 0           return $old;
120             }
121              
122             sub TO_JSON {
123 0     0 0   my ($self) = @_;
124 0           my $json = {
125             mimeType => $self->mime_type(),
126             size => $self->size(),
127             };
128 0 0         if ( defined $self->compression() ) {
129 0           $json->{compression} = $self->compression();
130             }
131 0 0         if ( defined $self->text() ) {
132 0           $json->{text} = $self->text();
133             }
134 0 0         if ( defined $self->encoding() ) {
135 0           $json->{encoding} = $self->encoding();
136             }
137 0 0         if ( defined $self->comment() ) {
138 0           $json->{comment} = $self->comment();
139             }
140 0           foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
  0            
  0            
141 0 0         next if ( !defined $self->{$key} );
142 0 0         if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
143 0           $json->{$key} = $self->{$key};
144             }
145             }
146 0           return $json;
147             }
148              
149             1;
150             __END__