File Coverage

blib/lib/SWIFT/Factory/ApplicationHeader.pm
Criterion Covered Total %
statement 29 45 64.4
branch 0 2 0.0
condition 0 3 0.0
subroutine 10 14 71.4
pod 3 3 100.0
total 42 67 62.6


line stmt bran cond sub pod time code
1             package SWIFT::Factory::ApplicationHeader;
2 1     1   14936 use strict;
  1         4  
  1         531  
3 1     1   10 use warnings;
  1         3  
  1         131  
4              
5 1     1   8 use vars qw($VERSION);
  1         15  
  1         69  
6             $VERSION='0.02';
7              
8 1     1   5 use constant MSG_PRIORITY_SYSTEM=>'S';
  1         2  
  1         93  
9 1     1   5 use constant MSG_PRIORITY_URGENT=>'U';
  1         1  
  1         44  
10 1     1   4 use constant MSG_PRIORITY_NORMAL=>'N';
  1         2  
  1         46  
11              
12 1     1   5 use constant MONITORING_NON_DELIVERY=>1;
  1         2  
  1         54  
13 1     1   5 use constant MONITORING_DELIVERY_NOTIFICATION=>2;
  1         1  
  1         43  
14 1     1   4 use constant MONITORING_DELIVERY_BOTH=>3;
  1         2  
  1         66  
15              
16             BEGIN{
17 1     1   3 *provide=*string;
18 1         919 *borken=*invalid;
19             }
20              
21             ###########################################################################################################
22             # The Application Header is block number 2 of a SWIFT message.
23             # This block is not required in all SWIFT messages.
24             #
25             # The block is normally built for "input", which in SWIFT
26             # speak means "input to the SWIFT network".
27             #
28             # This module will implement an "Input Application Header".
29             ###########################################################################################################
30              
31             ###########################################################################################################
32             # Class private stuff.
33             my$io_id_input=sub{'I'};
34             ###########################################################################################################
35              
36             ###########################################################################################################
37             # Constructor.
38             sub new {
39 0     0 1   my$self={};
40 0           bless($self,shift())->_init(@_);
41             }
42              
43             ###########################################################################################################
44             # The class cannot guarantee that the provided string will be valid in the SWIFT network.
45             # It can point out that it's found some invalid data, though.
46             # Return number of problems detected.
47             sub invalid {
48 0     0 1   my$self=shift;
49              
50             # Implement verifications here!
51 0           0;
52             }
53              
54             ###########################################################################################################
55             sub string {
56 0     0 1   my$self=shift;
57              
58 0 0 0       '{2:'.
59             $self->$io_id_input().
60             sprintf("%03u",$self->{MSG_TYPE}).
61             $self->{BIC}.
62             $self->{TERMINAL}.
63             $self->{BRANCH_CODE}.
64             $self->{MSG_PRIORITY}.
65             $self->{DELIVERY_MONITORING}.
66             (defined($self->{OBSOLESCENCE_PERIOD})&&length($self->{OBSOLESCENCE_PERIOD})?sprintf("%03u",$self->{OBSOLESCENCE_PERIOD}):'').
67             '}';
68             }
69              
70             ###########################################################################################################
71             ###########################################################################################################
72             #
73             # 'Internal' subs. Don't call these since they may, and will, change without notice.
74             #
75             ###########################################################################################################
76             ###########################################################################################################
77              
78             ###########################################################################################################
79             sub _init {
80 0     0     my$self=shift;
81 0           my%args=(
82             MESSAGE_TYPE=>0,
83             BIC=>'X'x8, # Receiver BIC for SWIFT input msg.
84             TERMINAL=>'X', # Receiver Terminal for SWIFT input msg.
85             BRANCH_CODE=>'X'x3, # Receiver Branch code for SWIFT input msg.
86             MESSAGE_PRIORITY=>MSG_PRIORITY_NORMAL,
87             DELIVERY_MONITORING=>'',
88             OBSOLESCENCE_PERIOD=>'',
89             @_
90             );
91              
92 0           $self->{MSG_TYPE}=$args{MESSAGE_TYPE};
93 0           $self->{BIC}=$args{BIC};
94 0           $self->{TERMINAL}=$args{TERMINAL};
95 0           $self->{BRANCH_CODE}=$args{BRANCH_CODE};
96 0           $self->{MSG_PRIORITY}=$args{MESSAGE_PRIORITY};
97 0           $self->{DELIVERY_MONITORING}=$args{DELIVERY_MONITORING};
98 0           $self->{OBSOLESCENCE_PERIOD}=$args{OBSOLESCENCE_PERIOD};
99              
100 0           $self;
101             }
102              
103             ###########################################################################################################
104             'Choppers rule';
105             __END__