r1394@llin: dpavlin | 2007-10-31 01:26:46 +0100
[webpac2] / lib / WebPAC / Common.pm
index e427cd3..5f42ba7 100644 (file)
@@ -1,4 +1,8 @@
 package WebPAC::Common;
+use Exporter 'import';
+@EXPORT = qw/
+       force_array
+/;
 
 use warnings;
 use strict;
@@ -169,6 +173,29 @@ sub var_path {
        return File::Spec->catfile('var', @_);
 }
 
+=head1 EXPORTED NETHODS
+
+=head2 force_array
+
+  my @array = force_array( $ref, sub {
+       warn "reference is undefined!";
+  });
+
+=cut
+
+sub force_array {
+       my ( $what, $error ) = @_;
+       my @result;
+       if ( ref( $what ) eq 'ARRAY' ) {
+               @result = @{ $what };
+       } elsif ( defined $what ) {
+               @result =  ( $what );
+       } else {
+               $error->() if ref($error) eq 'CODE';
+       }
+       return @result;
+}
+
 
 =head1 INTERNAL METHODS