File Coverage

blib/lib/Business/BancaSella/Encode.pm
Criterion Covered Total %
statement 38 40 95.0
branch 5 8 62.5
condition 2 6 33.3
subroutine 9 10 90.0
pod 1 4 25.0
total 55 68 80.8


line stmt bran cond sub pod time code
1             package Business::BancaSella::Encode;
2              
3             $VERSION = "0.11";
4 0     0 0 0 sub Version { $VERSION; }
5              
6             require 5.004;
7 1     1   852 use strict;
  1         2  
  1         42  
8 1     1   7 use Carp;
  1         2  
  1         93  
9              
10 1     1   640 use Business::BancaSella::Encode::Gestpay;
  1         3  
  1         48  
11 1     1   16516 use Business::BancaSella::Encode::Gateway;
  1         3  
  1         195  
12              
13             my %fields =
14             (
15             type => 'gestpay',
16             );
17            
18             my @fields_req = qw/type/;
19            
20             sub new
21             {
22 2     2 1 26 my $proto = shift;
23 2   33     14 my $class = ref($proto) || $proto;
24 2         3 my $self = {};
25 2         5 bless $self,$class;
26 2         8 $self->init(@_);
27 2         7 return $self;
28             }
29              
30             sub init {
31 2     2 0 3 my $self = shift;
32 2         15 my (%options) = @_;
33             # Assign default options
34 2         12 while (my ($key,$value) = each(%fields)) {
35 2   33     25 $self->{$key} = $self->{$key} || $value;
36             }
37             # Assign options
38 2         8 while (my ($key,$value) = each(%options)) {
39 11         34 $self->{$key} = $value
40             }
41             # Check required params
42 2         5 foreach (@fields_req) {
43 2 50       10 croak "You must declare '$_' in " . ref($self) . "::new"
44             if (!defined $self->{$_});
45             }
46 2 100       7 if ($self->type eq 'gestpay') {
    50          
47 1     1   4 no strict 'vars';
  1         2  
  1         39  
48 1         17 unshift @ISA,'Business::BancaSella::Encode::Gestpay';
49             } elsif ($self->type eq 'gateway') {
50 1     1   4 no strict 'vars';
  1         2  
  1         109  
51 1         19 unshift @ISA,'Business::BancaSella::Encode::Gateway';
52             } else {
53 0         0 die "Unsupported type " . $self->type . "in " . ref($self) . "::new";
54             }
55 2         22 $self->SUPER::init(@_);
56             }
57              
58              
59 3 50   3 0 4 sub type { my $s=shift; return @_ ? ($s->{type}=shift) : $s->{type} }
  3         19  
60              
61             # Preloaded methods go here.
62              
63             1;
64             __END__