dummy export module for testing
[freeside.git] / FS / FS / part_export / test.pm
1 package FS::part_export::test;
2
3 use strict;
4 use vars qw(%options %info);
5 use Tie::IxHash;
6 use base qw(FS::part_export);
7
8 tie %options, 'Tie::IxHash',
9   'result'  => { label    => 'Result',
10                  type     => 'select',
11                  options  => [ 'success', 'failure', 'exception' ],
12                  default  => 'success',
13                },
14   'errormsg'=> { label    => 'Error message',
15                  default  => 'Test export' },
16   'insert'  => { label    => 'Insert', type => 'checkbox', default => 1, },
17   'delete'  => { label    => 'Delete', type => 'checkbox', default => 1, },
18   'replace' => { label    => 'Replace',type => 'checkbox', default => 1, },
19   'suspend' => { label    => 'Suspend',type => 'checkbox', default => 1, },
20   'unsuspend'=>{ label => 'Unsuspend', type => 'checkbox', default => 1, },
21 ;
22
23 %info = (
24   'svc'     => [ qw(svc_acct svc_broadband svc_phone svc_domain) ],
25   'desc'    => 'Test export for development',
26   'options' => \%options,
27   'notes'   => <<END,
28 <P>Test export.  Do not use this in production systems.</P>
29 <P>This export either always succeeds, always fails (returning an error),
30 or always dies, according to the "Result" option.  It does nothing else; the
31 purpose is purely to simulate success or failure within an export module.</P>
32 <P>The checkbox options can be used to turn the export off for certain
33 actions, if this is needed.</P>
34 END
35 );
36
37 sub export_insert {
38   my $self = shift;
39   $self->run(@_) if $self->option('insert');
40 }
41
42 sub export_delete {
43   my $self = shift;
44   $self->run(@_) if $self->option('delete');
45 }
46
47 sub export_replace {
48   my $self = shift;
49   $self->run(@_) if $self->option('replace');
50 }
51
52 sub export_suspend {
53   my $self = shift;
54   $self->run(@_) if $self->option('suspend');
55 }
56
57 sub export_unsuspend {
58   my $self = shift;
59   $self->run(@_) if $self->option('unsuspend');
60 }
61
62 sub run {
63   my $self = shift;
64   my $svc_x = shift;
65   my $result = $self->option('result');
66   if ( $result eq 'failure' ) {
67     return $self->option('errormsg');
68   } elsif ( $result eq 'exception' ) {
69     die $self->option('errormsg');
70   } else {
71     return '';
72   }
73 }
74
75 1;