File Coverage

blib/lib/StateML/Utils.pm
Criterion Covered Total %
statement 10 10 100.0
branch 5 8 62.5
condition 3 3 100.0
subroutine 4 4 100.0
pod 2 2 100.0
total 24 27 88.8


line stmt bran cond sub pod time code
1             package StateML::Utils;
2              
3             $VERSION = 0.000_1;
4              
5             =head1 NAME
6              
7             StateML::Utils - Some handy utility functions
8              
9             =head1 SYNOPSIS
10              
11             use StateML::Utils qw( empty as_string );
12              
13             =head1 DESCRIPTION
14              
15             Some handy uti.... you get the idea.
16              
17             =cut
18              
19             @EXPORT_OK = qw( empty as_str );
20             %EXPORT_TAGS = ( all => \@EXPORT_OK );
21             @ISA = qw( Exporter );
22 4     4   8570 use Exporter;
  4         9  
  4         166  
23              
24 4     4   26 use strict;
  4         7  
  4         579  
25              
26             =head1 FUNCTIONS
27              
28             =over
29              
30             =cut
31              
32             =item empty
33              
34             Returns TRUE if the single arg is not defined or of zero length. "0" is
35             not empty. This does not have a prototype like defined() or length() because
36             the precedance can't be set properly. Tests $_ if no parameters are passed.
37              
38             =cut
39              
40             sub empty {
41 5 50   5 1 2405 local $_ = shift if @_;
42 5   100     45 return ! ( defined && length );
43             }
44              
45             =item as_str
46              
47             warn as_str "hey!", undef.
48              
49             Converts the list of parameters to a string, quoting plain scalars
50             if need be and reporting them as undef if they are undefined. May
51             handle other situations/structures in the future.
52              
53             Does an implicit join( "", ... ) in scalar context.
54              
55             =cut
56              
57             sub as_str {
58 2 100   2 1 431 my @out = map
    50          
59             ref $_ ? ref $_ : defined $_ ? "'$_'" : "undef",
60             @_;
61              
62 2 50       17 return wantarray ? @out : join "", @out;
63             }
64              
65             =back
66              
67             =head1 LIMITATIONS
68              
69             =head1 COPYRIGHT
70              
71             Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
72              
73             =head1 LICENSE
74              
75             You may use this module under the terms of the BSD, Artistic, or GPL licenses,
76             any version.
77              
78             =head1 AUTHOR
79              
80             Barrie Slaymaker
81              
82             =cut
83              
84             1;