blib/lib/auto/share/dist/Games-Axmud/plugins/mxpfilter.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 61 CC 5 SCAR 26.9
CC
5
Cov
0%
convertFile
30.0
BEGIN
2.0
END
2.0
CRAP 14.7
1 #!/usr/bin/perl
2 package mxpfilter;
3 #: Version: 1.0
4 #: Description: Example of a plugin that implements MXP image/sound filters
5 #: Author: A S Lewis
6 #: Copyright: This plugin is in the public domain, but you are encouraged to share any modifications
7 # and improvements you make!
8  
9 # =-=-=-=-=-=-=-=-=-=
10 # PLUGIN INSTRUCTIONS
11 # =-=-=-=-=-=-=-=-=-=
12 #
13 # MXP (Mud eXtension Protocol) allows a world to specify its own image/sound format. The world
14 # must also provide a client plugin which converts the image/sound file into one which the
15 # client supports. In this way, the world can prevent the user from viewing image files and/or
16 # hearing sound files until they are required.
17 # This plugin demonstrates how to write such a plugin for Axmud. MU* Administrators can modify it
18 # to suit their own needs.
19 #
20 # 1. Rename the plugin from 'mxpfilter' to something else, if you want. Modify lines 2 and 47.
21 #
22 # 2. Every time Axmud tries to apply an MXP file filter, a function in this plugin is called. This
23 # plugin uses a function called &convertFile(). If you want to rename the function, modify
24 # lines 48 and 51.
25 #
26 # 3. The code which performs the conversion starts at line 101. Modify it in any way you please.
27  
28 use strict;
29 #use diagnostics;
30 use warnings;
31  
32 use File::Copy qw(copy);
33  
34 # Modules used by this plugin
35 # (none)
36  
37 # Standard BEGIN / END functions
38 BEGIN {
39  
40 use Glib qw(TRUE FALSE);
41 }
42  
43 END {}
44  
45 # Inform the client which this plugin's functions should be called
46 $axmud::CLIENT->addPluginMxpFilters(
47 'mxpfilter', # The name of this plugin
48 \&convertFile, # The name of the conversion function defined below
49 );
50  
51 sub convertFile {
52  
53 # Called by GA::Session->processMxpImageElement and ->processMspSoundTrigger
54 # Converts an image/sound file in the world's own file format into a file format supported by
55 # the client. This example function could convert a .gff file into a .gif file
56 #
57 # Expected arguments
58 # $path - The full file path of the file to convert, e.g.
59 # '/home/myname/axmud_data/mxp/deathmud/myimage.gff'
60 # $src - The source file extension specified by the MXP <FILTER> tag, e.g. 'gff'
61 # $dest - The destination file extension specified by the MXP <FILTER> tag, e.g. 'gif'
62 # $proc - An optional numerical parameter used to support multiple conversions, as needed
63 # (see the MXP spec). Default value is 0
64 #
65 # Return values
66 # 'undef' on improper arguments
67 # Otherwise, returns the full file path of the converted file, e.g.
68 # '/home/myname/axmud_data/mxp/deathmud/myimage.gif'
69 # 1 otherwise
70  
71 my ($path, $src, $dest, $proc, $check) = @_;
72  
73 # Local variables
74 my $newPath;
75  
76 # Check for improper arguments
77 if (! defined $path || ! defined $src || ! defined $dest || ! defined $proc || defined $check) {
78  
79 return $axmud::CLIENT->writeImproper('&convertFile', @_);
80 }
81  
82 # Check that the file actually exists (this check has already been done, but there's no harm
83 # doing it again)
84 if (! -e $path) {
85  
86 return undef;
87 }
88  
89 # Check that the file has the right file extension. For example, check that it's a .gff file
90 if (! ($path =~ m/\.$src$/)) {
91  
92 return undef;
93 }
94  
95 # Convert the file from the world's own file format into one supported by the client
96 # In this example plugin, we'll 'convert' the file by changing its file extension, but your
97 # plugin will have to do an actual conversion of some kind
98 # If you want a temporary directory to work in, you can use ../axmud_data/tmp/
99 # Files in ../axmud_data/tmp/ are deleted whenever the client starts and stops but, in any case,
100 # the calling function will delete the converted file as soon as it's used
101 $newPath = $path;
102 $newPath =~ s/$src$/$dest/;
103  
104 if (! File::Copy::copy($path, $newPath)) {
105  
106 return undef;
107  
108 } else {
109  
110 return $newPath;
111 }
112 }
113  
114 # Package must return a true value
115 1