You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Terrence Brannon <pr...@yahoo.com> on 2000/02/21 17:52:46 UTC

a difference between Embperl and Mason: typeglob support

In DBIx::Recordset, typeglobs are used to encapsulate
three modes: the scalar allows you to access Recordset
methods, the array it used to iterate through the
results of a select, and the hash is used to access
the fields of the current record.

While I thought this was cute initially, due to some
apparent limitation of HTML::Mason, typeglobs cannot
be passed directly to components though they can be
passed directly to perl subroutines.

Had DBIx::Recordset simply made the array and hash
parts of an object then they could be used within the
limitations of HTML::Mason.

Alternatively, one could use Embperl which has none of
the limitations on Perl that Mason has, all of which
seem to be primarily in the domain of argument
passing.

Welp, off to send a reference to a glob into a Mason
and dereference it...


sub output_glob {

    $eval=$_[0];
    *tmp=eval("*$eval");


    $FIELD='Description';
    my %field = ('$fields'     => "$FIELD",
                 '$order'      => $order_field ?
$order_field : '');

    $tmp -> Search(\%field);

    print "Results ", 1+$#tmp, $/;

}






=====
Terrence Brannon
2041 Business Center Drive
Suite 214
(877) 411-7070 x 182 (toll-free voice)
949-623-8071 (FAX)
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

RE: [Mason] a difference between Embperl and Mason: typeglob support

Posted by Gerald Richter <ri...@ecos.de>.
>
> In DBIx::Recordset, typeglobs are used to encapsulate
> three modes: the scalar allows you to access Recordset
> methods, the array it used to iterate through the
> results of a select, and the hash is used to access
> the fields of the current record.
>
> While I thought this was cute initially, due to some
> apparent limitation of HTML::Mason, typeglobs cannot
> be passed directly to components though they can be
> passed directly to perl subroutines.
>
> Had DBIx::Recordset simply made the array and hash
> parts of an object then they could be used within the
> limitations of HTML::Mason.
>

Typeglobs are only one way to setup DBIx::Recordset. You can setup the array
and hash and object on it's own. For example:

my @arr ;
my %hash ;

my $set = tie @arr, 'DBIx::Recordset', {'!DataSource' => 'dbi:mysql:test',
'!Table' => 'foo'} ;

tie %hash, 'DBIx::Recordset::Hash', {'!DataSource' => $set, '!Table' =>
'foo'} ;

now you have an normal scalar, array and hash to pass around. The other
possibility is to assign the typeglob to a scalar:

my $set = DBIx::Recordset -> Search ({'!DataSource' => 'dbi:mysql:test',
'!Table' => 'foo'}) ;

Now you can access the array elements via

$set -> [$i]

the hash elements via

$set -> {'fieldname'}

and the object via

$$set

You see Perl turns the typeglob into a reference to that typeglob, and now
you are able to pass it around.

Hope this helps

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------