Re: Including externally-defined constants
* David Landgren [EMAIL PROTECTED] [2006-07-21 11:30]: My only regret is that the Cuse constant {} construct only became legal in 5.8, and I don't think the tradeoff between the admittedly remarkable ease of use of this compared to cutting off 5.5, 5.6 is worthwhile. Well you can easily do without the hashref syntax, the code just ends up looking busier. BEGIN { my %const; use Pod::Constants -trim = 1, constants = \%const; require constant; constant-import( $_ = $const{ $_ } ) for keys %const; } Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: Including externally-defined constants
Le jeudi 20 juillet 2006 à 02:41, A. Pagaltzis écrivait: * Philippe BooK Bruhat [EMAIL PROTECTED] [2006-07-19 22:10]: '=cut'; =pod [...snip...] =cut Damn, what a cool hack! That's exactly what I thought when I first saw it. :-) -- Philippe BooK Bruhat A substitute is never as good as the genuine article. (Moral from Groo The Wanderer #67 (Epic))
Re: Including externally-defined constants
* Philippe BooK Bruhat [EMAIL PROTECTED] [2006-07-20 08:40]: Le jeudi 20 juillet 2006 à 02:41, A. Pagaltzis écrivait: * Philippe BooK Bruhat [EMAIL PROTECTED] [2006-07-19 22:10]: '=cut'; =pod [...snip...] =cut Damn, what a cool hack! That's exactly what I thought when I first saw it. :-) I just abused it further, check it out: http://www.perlmonks.org/index.pl?node_id=562735 Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: Including externally-defined constants
* David Landgren [EMAIL PROTECTED] [2006-07-19 13:40]: The problem is that these associations are private to the XS and Perl module. The client code does not need to know about them, and in fact shouldn't. So I don't want client code to know the file exists, and people won't go around trying to include it. So the Perl file has to go. Might Pod::Constants help? =begin constants FOO = 1 BAR = 2 QUUX = 3 =end constants And then in the code: use Pod::Constants -trim = 1, constants = \my %const; use constants \%const; Then you generate the C header out of the Perl module in the same way: use Pod::Constants; import_from_file lib/Foo/Bar.pm, -trim = 1, constants = \my %const; while( my ( $key, $val ) = each %const ) { print #define $key $val\n; } Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: Including externally-defined constants
Le mercredi 19 juillet 2006 à 13:59, A. Pagaltzis écrivait: * David Landgren [EMAIL PROTECTED] [2006-07-19 13:40]: The problem is that these associations are private to the XS and Perl module. The client code does not need to know about them, and in fact shouldn't. So I don't want client code to know the file exists, and people won't go around trying to include it. So the Perl file has to go. Might Pod::Constants help? =begin constants FOO = 1 BAR = 2 QUUX = 3 =end constants In the same vein, and without an external module, you could also simply expose the information in the documentation, and fetch it from there: (a trick I discovered thanks to Abigail's additions to Acme::MetaSyntactic, see the upcoming Acme::MetaSyntactic::tour_de_france for an example): my %const = map { s/\s+//; $_ } map { split /\s*=\s*/ } grep {/=/} map { split /\n/ } '=cut'; =pod This module uses the following constants: bang_eth = 1 biff = 2 krunch = 3 =cut -- Philippe BooK Bruhat There are two sides to every cause. Do not join one until you know the other. (Moral from Groo The Wanderer #105 (Epic))
Re: Including externally-defined constants
* Philippe BooK Bruhat [EMAIL PROTECTED] [2006-07-19 22:10]: '=cut'; =pod [...snip...] =cut Damn, what a cool hack! Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;