NAME
Device::ScanShare - manage USERDIRTS.TXT ecopy file to manage scanner device options
SYNOPSYS
use Device::ScanShare;
my $scanshare = new Device::ScanShare({
userdirs_abs_path => '/var/www/Content/USERDIRS.TXT',
# therefore all paths saved are /var/www/Content/$PATH
server => '192.168.0.150',
default_host => 'Dyer05',
});
$scanshare->user_add({
label=>'Martin',
path=>'/home/martin/incoming',
});
$scanshare->save;
WHY
We use ecopy and sharescan software in the office. This is so someone can step up to the scanner and scan to a predetermined place. They have a little touchscreen.. you punch in where you want to send it to, the name of the file, and voila. What you can select from is controlled via a file called USERDIRS.TXT. In it are entries like
The Label=relative\dir\path,The Label,HostName,1,0
You can edit the damn thing in a text editor. If you have a jillion entries (like we have, upwards of 500), then you do not want to micro manage this by either using their crippled interface or via a text editor. Linux and perl to the rescue.
Included is also a utility called sharescan that will let you edit the file via the command line.
DESCRIPTION
ScanShare is a oo module to work with the USERDIRS.TXT file used by ecopy for use with their ShareScan software. This enables you to control what the entries are via perl. You can add and remove entries to the file.
PUBLIC METHODS
new()
constructor, initiates object. takes as argument the path to the userdirs file, the server ip as per USERDIRS.TXT, and the host for each line (Dyer05)
my $scanshare = new Device::ScanShare({
userdirs_abs_path => '/var/www/Content/USERDIRS.TXT',
server => '192.168.0.150',
default_host => 'Dyer05',
});
create()
will create a new USERDIRS.TXT file in the argument provided to the constructor. That is, if you want to create a new file:
my $s = new Device::ScanShare({
userdirs_abs_path => cwd().'/t/USERDIRS.txt',
server => '192.168.0.150',
default_host => 'Dyer05',
});
$s->create;
create() will return true or false, will carp if file already exists or if create is not successful.
exists()
returns boolean, checks if userdirs file exists already or not in the argument provided.
get_users()
Returns array ref with hashes of data for each userdirs entry- if you have made any additions or removals, this is reflected. Results are orderded by label.
This method is also used internally to save.
my @all = $scanshare->get_users();
user_add() and user_delete()
Please note user_add() and user_delete() will save changes to the file.
user_add()
insert new userdir into records, takes arguments label, and absolute path. returns 0 if it already exists (by path), returns 1 on success.
my $path = '/path/to/dirx';
my $label = 'a new scan destination';
$scanshare->user_add({ label=>$label, path=>$path })
or die("entry already existed for the destination $path");
please note t
user_delete()
delete user record, takes absolute path to directory that it saves to as argument
$scanshare->user_delete('/path/to/target_directory');
$scanshare->save(); # optionally save it to commit changes.
returns 1 on success returns nothing if entry did not exist
get_user()
get userdirs line entry data by path, returns hash
my $userx = $scanshare->get_user('/path/to/target_directory');
print $userx->{label} . ' is set up to scan to directory: '. $userx->{path};
save()
save changes to userdirs file
$scanshare->save();
count()
returns how many userdirs there are
my $count = $scanshare->count();
PRIVATE METHODS
NOTES
Example of a valid USERDIRS.TXT file:
[PreferredServer]
Server=192.168.0.130
[RoutingID]
NextID=4
[Users]
Great Place=relative\to\userdirs\location,Great Place,Host04,1,0
Also a Great Place=relative\also,Also a Great Place,Host04,2,0
Documents=misc\documents,Documents,Host04,3,0
Note the increment 1, 2, 3..
AUTHOR
Leo Charre leocharre at cpan dot org