karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, here is what i did:
package Karl::Fractals::Mandelbrot; use Moo; use strictures 1; use namespace::clean; use Inline C => 'DATA'; sub reckon { my ( $self, $x, $y ) = @_; mandelbrot( $x, $y ); } has iterations => ( is => 'ro', default => 20 ); has width => ( is => 'ro', default => 1280 ); has height => ( is => 'ro', default => 1024 ); 1; __DATA__ __C__ /* fake */ int mandelbrot(int x, int y) { return x*y; }
#!/usr/bin/env perl use strict; use warnings; use lib q(.); use Karl::Fractals::Mandelbrot; use feature qw (say); use Data::Dump; my $Benoit = Karl::Fractals::Mandelbrot->new(); dd $Benoit; say $Benoit->reckon( 2, 7 ); __END__ karls-mac-mini:monks karl$ ./inline_moo.pl bless({ height => 1024, iterations => 20, width => 1280 }, "Karl::Frac +tals::Mandelbrot") 1280 1024 20 14
Somehow related to some of my previous posts.
This very simplified example works as expected.
But i wonder if it is good practice. Perhaps some unexpected traps?
BTW, I didn't use Inline::C except for "Hello World!" until now.
Thank you very much for any hint and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: About Moo and Inline::C
by marioroy (Prior) on Jun 10, 2015 at 01:10 UTC | |
by karlgoethebier (Abbot) on Jun 10, 2015 at 14:21 UTC | |
|
Re: About Moo and Inline::C
by davido (Cardinal) on Jun 10, 2015 at 06:03 UTC | |
by marioroy (Prior) on Jun 10, 2015 at 10:55 UTC | |
by karlgoethebier (Abbot) on Jun 10, 2015 at 14:23 UTC |