File Coverage

blib/lib/WebService/PagerDuty/Base.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 2 2 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl -w
2              
3             ## workaround for PkgVersion
4             ## no critic
5             package WebService::PagerDuty::Base;
6             {
7             $WebService::PagerDuty::Base::VERSION = '1.20131219.1627';
8             }
9             ## use critic
10 2     2   103 use strict;
  2         5  
  2         77  
11 2     2   10 use warnings;
  2         3  
  2         50  
12 2     2   2347 use Class::Accessor;
  2         5990  
  2         17  
13              
14 2     2   105 use base qw/ Class::Accessor /;
  2         4  
  2         726  
15              
16             __PACKAGE__->mk_ro_accessors(qw/ _defaults _init_args /);
17              
18             sub new {
19 6     6 1 58 my $self = shift;
20 6         33 my $args = {@_}; # copy
21 6 100       32 $args->{_defaults} = {} unless exists $args->{_defaults};
22 6         35 my $init = {%$args}; # copy
23 6         18 delete $init->{_defaults};
24 6         69 $self->SUPER::new( { _init_args => $init, %$args } );
25             }
26              
27             sub get {
28 22     22 1 30058 my $self = shift;
29 22         42 my $field = shift;
30              
31 22         75 my $defaults = $self->{_defaults};
32 22         96 my $init_args = $self->{_init_args};
33              
34 22 100 100     180 if ( !exists( $init_args->{$field} ) && exists( $defaults->{$field} ) ) {
35 2         7 $init_args->{$field} = 'lazy_build';
36 2         13 $self->{$field} = $defaults->{$field}->($self);
37             }
38             else {
39 20         88 $self->SUPER::get( $field, @_ );
40             }
41             }
42              
43             1;
44              
45             __END__