You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Gerald Richter <ri...@ecos.de> on 2000/02/21 20:26:21 UTC

RE: [Mason] 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.
>

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
-------------------------------------------------------------