Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.234.136 Times

Contextual::Return 0.1.0

  Date Added: October 20, 2010  |  Visits: 821

Contextual::Return

Report Broken Link
Printer Friendly Version


Product Homepage
Download (97 downloads)



Contextual::Return is a Perl module to create context-senstive return values. SYNOPSIS use Contextual::Return; use Carp; sub foo { return SCALAR { thirty-twelve } BOOL { 1 } NUM { 7*6 } STR { forty-two } LIST { 1,2,3 } HASHREF { {name => foo, value => 99} } ARRAYREF { [3,2,1] } GLOBREF { *STDOUT } CODEREF { croak "Dont use this result as code!"; } ; } # and later... if (my $foo = foo()) { for my $count (1..$foo) { print "$count: $foo is:n" . " array: @{$foo}n" . " hash: $foo->{name} => $foo->{value}n" ; } print {$foo} $foo->(); } Usually, when you need to create a subroutine that returns different values in different contexts (list, scalar, or void), you write something like: sub get_server_status { my ($server_ID) = @_; # Acquire server data somehow... my %server_data = _ascertain_server_status($server_ID); # Return different components of that data, # depending on call context... if (wantarray()) { return @server_data{ qw(name uptime load users) }; } if (defined wantarray()) { return $server_data{load}; } if (!defined wantarray()) { carp Useless use of get_server_status() in void context; return; } else { croak q{Bad context! No biscuit!}; } } That works okay, but the code could certainly be more readable. In its simplest usage, this module makes that code more readable by providing three subroutines--LIST(), SCALAR(), VOID()--that are true only when the current subroutine is called in the corresponding context: use Contextual::Return; sub get_server_status { my ($server_ID) = @_; # Acquire server data somehow... my %server_data = _ascertain_server_status($server_ID); # Return different components of that data # depending on call context... if (LIST) { return @server_data{ qw(name uptime load users) } } if (SCALAR) { return $server_data{load} } if (VOID) { print "$server_data{load}n" } else { croak q{Bad context! No biscuit!} } } Contextual returns Those three subroutines can also be used in another way: as labels on a series of contextual return blocks (collectively known as a context sequence). When a context sequence is returned, it automatically selects the appropriate contextual return block for the calling context. So the previous example could be written even more cleanly as: use Contextual::Return; sub get_server_status { my ($server_ID) = @_; # Acquire server data somehow... my %server_data = _ascertain_server_status($server_ID); # Return different components of that data # depending on call context... return ( LIST { return @server_data{ qw(name uptime load users) } } SCALAR { return $server_data{load} } VOID { print "$server_data{load}n" } DEFAULT { croak q{Bad context! No biscuit!} } ); } The context sequence automatically selects the appropriate block for each call context..

Requirements: No special requirements
Platforms: Linux
Keyword: Context Contextualreturn Data Foo Id Libraries List Load Perl Module Return Scalar Server To Create Void
Users rating: 0/10

License: Freeware Size: 22.53 KB
USER REVIEWS
More Reviews or Write Review


CONTEXTUAL::RETURN RELATED
Libraries  -  List::Util 1.19
List::Util Perl module contains a selection of general-utility list subroutines. SYNOPSIS use List::Util qw(first max maxstr min minstr reduce shuffle sum); List::Util contains a selection of subroutines that people have expressed would be...
44.03 KB  
Libraries  -  List::Part 0.03
List::Part is a Perl module that allows you to partition one array into several. SYNOPSIS use List::Part; ($good, $bad)=part { !/substring/ } @array; #store arrayrefs into $good and $bad (*good, *bad)=part { !/substring/ } @array; #store...
4.1 KB  
Libraries  -  List::Intersperse 1.00
List::Intersperse Perl module can intersperse / unsort / disperse a list. SYNOPSIS use List::Intersperse qw/intersperseq/; @ispersed = intersperseq {substr($_[0],0,1)} qw/A1 A2 B1 B2 C1 C2/; @ispersed = List::Intersperse::intersperse qw/A...
2.05 KB  
Libraries  -  File::Data 1.12
File::Data is a Perl module as a interface to file data. Wraps all the accessing of a file into a convenient set of calls for reading and writing data, including a simple regex interface. Note that the file needs to exist prior to using this...
13.31 KB  
Libraries  -  Lingua::ID::Nums2Words 0.01
Lingua::ID::Nums2Words is a Perl module to convert number to Indonesian verbage. SYNOPSIS use Lingua::ID::Nums2Words ; print nums2words(123) ; # "seratus dua puluh tiga" print nums2words_simple(123) ; # "satu dua tiga" nums2words...
3.07 KB  
Libraries  -  Test::Data 1.20
Test::Data is a Perl module to test functions for particular variable types. SYNOPSIS use Test::Data qw(Scalar Array Hash Function); Test::Data provides utility functions to check properties and values of data and variables. Functions...
8.19 KB  
Libraries  -  Data::Page::Viewport 1.02
Data::Page::Viewport is a Perl module to scroll thru data a page, or just an item, at a time. Synopsis This is a complete, tested, runnable program. #!/usr/bin/perl use strict; use warnings; use Data::Page::Viewport; #...
8.19 KB  
Libraries  -  Test::Differences 0.47
Test::Differences Perl module contains test strings and data structures and show differences if not ok. SYNOPSIS use Test; ## Or use Test::More use Test::Differences; eq_or_diff $got, "anbncn", "testing strings"; eq_or_diff @got, [qw( a b...
8.19 KB  
Database Tools  -  Data Export 2011 for Oracle 3.4.0.6
Data Export for Oracle is an complete application that helps you to create MySQL database backups using SQL scripts. This database script utility allows you to save metadata of all MySQL database objects as well as MySQL table data as database...
 
Snippets  -  create array from comma separated list 1.0
create array from comma separated list script uses the PHP Explode() command to create an array from a comma separated list.By changing the delimiter you can convert tab separated, newline separated, etc...
 
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB