File Coverage

blib/lib/SWIFT/Factory/Tag/Tag21.pm
Criterion Covered Total %
statement 14 34 41.1
branch 0 14 0.0
condition 0 3 0.0
subroutine 5 12 41.6
pod 5 5 100.0
total 24 68 35.2


line stmt bran cond sub pod time code
1             package SWIFT::Factory::Tag::Tag21;
2 1     1   8084 use strict;
  1         2  
  1         40  
3 1     1   7 use warnings;
  1         2  
  1         57  
4              
5             ###########################################################################################################
6             # Provide a SWIFT TAG 21.
7             #
8             # Use this class to provide a Related Reference.
9             #
10             ###########################################################################################################
11              
12             BEGIN{
13 1     1   3 *provide=*string;
14 1         36 *borken=*invalid;
15             }
16              
17 1     1   5 use vars qw($VERSION);
  1         2  
  1         66  
18             $VERSION='0.01';
19              
20 1     1   12 use constant REF_MAX_LEN=>16;
  1         2  
  1         478  
21              
22             ###########################################################################################################
23             sub new {
24 0     0 1   my$self={};
25 0           bless($self,shift())->_init(@_);
26             }
27              
28             ###########################################################################################################
29             # The class cannot guarantee that the TAG will be valid in the SWIFT network.
30             # It can point out that it's found some invalid data, though.
31             # Return number of problems detected.
32             sub invalid {
33 0     0 1   my$self=shift;
34              
35             # Implement verifications here!
36 0           0;
37             }
38              
39             ###########################################################################################################
40             sub ref_max_len {
41 0     0 1   REF_MAX_LEN;
42             }
43              
44             ###########################################################################################################
45             # If a new Reference is provided, store it for future use.
46             # If requested, return the stored Reference to the caller.
47             sub reference {
48 0     0 1   my($self,$reference)=@_;
49 0 0         defined($reference)&&$self->_store_reference($reference);
50 0 0         return(defined(wantarray)?wantarray?($self->{REFERENCE}):$self->{REFERENCE}:undef);
    0          
51             }
52              
53             ###########################################################################################################
54             sub string {
55 0     0 1   my$self=shift;
56 0           ':21:'.
57             $self->{REFERENCE}.
58             chr(13). # CR
59             chr(10); # LF
60             }
61              
62             ###########################################################################################################
63             ###########################################################################################################
64             #
65             # 'Internal' subs. Don't call these since they may, and will, change without notice.
66             #
67             ###########################################################################################################
68             ###########################################################################################################
69              
70             ###########################################################################################################
71             sub _init {
72 0     0     my$self=shift();
73 0           my%args=(
74             DO_CLEANUP=>0,
75             REFERENCE=>'',
76             @_);
77              
78 0 0         $self->{DO_CLEANUP}=defined($args{DO_CLEANUP})?$args{DO_CLEANUP}?1:0:0;
    0          
79 0           $self->_store_reference($args{REFERENCE});
80 0           $self;
81             }
82              
83             ###########################################################################################################
84             # If Reference is defined, store it together with some simple cleanup applied.
85             sub _store_reference {
86 0     0     my($self,$reference)=@_;
87              
88 0 0         defined($reference)||return;
89              
90 0 0 0       $self->{DO_CLEANUP}&&length($reference)>REF_MAX_LEN&&do{
91             # Apply conditional warnings here!
92 0           $reference=substr($reference,0,REF_MAX_LEN);
93             };
94              
95 0           $self->{REFERENCE}=$reference;
96             }
97              
98             ###########################################################################################################
99             'Choppers rule';
100             __END__