Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
http://returnvalues.useperl.at/

42 seems to be another commonly used one.

Mario Incandenza fucked around with this message at 07:00 on Nov 19, 2008

Adbot
ADBOT LOVES YOU

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Best practices for global configuration data? I'm leaning towards handing out a JSON struct via REST, as it's a fair bit quicker than reading a file off disk and doesn't go stale as easily. Am starting to feel the pain of redundant configuration files.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Customer-facing and staff-only Catalyst apps, scripts that get run in crontab, and daemon processes, spread across geographically separate machines. For example, we have a cluster of RPC servers that talk to SMPP gateways, domain registries, that sort of thing, and it would be nice to have some sort of common method of specifying service details from both sides (e.g. from Catalyst when sending an SMS, or from the RPC server when processing a delivery receipt for the same).

I could just as easily use YAML, Storable or DDS, but then I don't get the benefits of native browser support.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Also, I'm not sure you need to use Tie::Handle::CSV when this is probably a lot faster:
code:
use Text::CSV_XS;

open my $csv_fh, '<', 'blah.csv';
my $csv = Text::CSV_XS->new;
$csv->column_names($csv->getline($csv_fh));

while (my $hashref = $csv->getline_hr) {
}

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Without having looked at the code and judged its portability to p6, App::Asciio might be a good starting point.

Rakudo is definitely way faster than Pugs was, though.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

bbatter posted:

Second one up, it'd benefit quite a bit if the interface could have a status bar (similar to screen's hardstatus). Does anyone know of a nice way of doing this? It wouldn't be the end of the world if the Term::UI stuff had to go
Curses::UI? Its label subclass does what you need:
code:
my $cui = Curses::UI->new(-color_support => 1);

my $win = $cui->add('window_id', 'Window');

my $label = $win->add(
   mylabel       => 'Label',
  -text          => 'dongs',
  -width         => -1,
  -textalignment => 'left',
  -height        => 1,
  -y             => -1,
);
$label->draw;

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
It's also a handy idiom if you want to merge two hashes:
code:
  my (%left, %right);
  @left{keys %right} = values %right;

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

adante posted:

Unfortunately it starts throwing (not in any particularly systematic manner, sometimes it does and sometimes it doesn't) this sort of error.
http://search.cpan.org/~timb/DBI/DBI.pm#Threads_and_Thread_Safety

At the moment you're creating your $dbh at compile time, since the instantiation takes place when the package is pulled in by mod_perl. If you create it at run-time closer to when it's needed, as opposed to at startup, the errors should stop occurring. You may still cache the handle between requests, however you need to make sure you connect after the thread itself is created (otherwise it will be shared between threads, and blow up when you use it).

The easiest way would be to make a get_dbh() function that connects the first time it's called, and just returns the existing handle every subsequent time.

Mario Incandenza fucked around with this message at 21:32 on Mar 22, 2009

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Just because you can doesn't mean you should. Why not:
code:
my $list = $res->{cat}{slist};

if (@$list > 1) {
}

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
As of 5.7007, calling $c->view() will honour the default_view setting in your config before checking $c->stash->{current_view} and then walking through the list of loaded View classes:

http://search.cpan.org/~mramberg/Catalyst-Runtime-5.71001/lib/Catalyst.pm#$c-%3Eview($name)

So yes, that's the case. You may set up content-type/accept sniffing in your end method and jump out to the appropriate view, e.g. TT, JSON or Email, for example.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Also, if you're using Catalyst::Action::RenderView, which gets enabled by default with the end controller in Root, it will only try to call a view's process() method if no HTTP body has been defined, so you can jump out to an arbitrary view from a given controller method, if you have to.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Catalyst 5.8000_07 hit CPAN today. Apparently a production-ready release will be made this week if no more blockers show up during testing. Time to start porting our existing apps over to Catamoose!

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

dagard posted:

Ideally, I'd like something that, either in Catalyst or TT2, I can go 'ok, for this page, this render, cache everything'
Catalyst::Plugin::PageCache . Supports Memcache etc.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
KiokuDB is pretty rad. Set up a test cluster of memcachedb machines and am writing a backend using libmemcached to see how much better/worse it is than CouchDB, which seemed to support about 1000 transactions/sec with replication enabled. Using MooseX::Declare makes it really weird to write Perl-but-not-Perl.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Am working with Unicode text files. To reliably get UTF16 I have to use the crazy open mode of:
code:
open my $fh, '<:raw:encoding(UTF-16LE):crlf:utf8', $filename;
But this then breaks ANSI and UTF8 text files so I need to close and re-open using a different mode, depending on whether the file starts with a BOM. Is there no open() mode string that will magically support any encoding without having to jump through hoops?

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Did you take a look at SQL::Abstract? It underpins DBIx::Class.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
You don't really need perl for that, since the rest isn't anyway. Might as well replace for movie in /home/smartdata/www/html/files/encode/mp4/720p/*.* with for movie in $(find /home/smartdata/www/html/files/encode/mp4/720p/ -type f -mmin +5). This lists only files that haven't been modified in the last 5 minutes.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
The call to read() advances the position of the filehandle, so you'll need to call seek() again before print(). And probably also remove the > after $filename.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Not really, no.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
code:
foreach my $book (@booklist) {
  say "$_ => $book->{$_}" for sort keys %$book;
}

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

Sartak posted:

code:
no warnings 'redefine';
I think redefine warnings only get triggered when you've got a sub foo declaration that overwrites an existing one, I'm not sure if assigning directly to a glob will raise it. In this case no warnings 'once' is probably the one Mithaldu's looking for.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Moose roles, types + coercion, and MX::AH have greatly improved my quality of life at work, no exaggeration. The time I used to spend writing fiddly low-level bullshit I now use making more classes and glue, it's awesome.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
The new treemap looks really useful.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
FYI if anybody still hasn't heard, Perlmonks was hacked along with Mitnick and Kaminsky, admin/saint passwords from September 2008 were leaked but it's likely all accounts were affected.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
This works a little nicer, it leaves each message on screen for at least one second and leaves it there until another arrives:
code:
tail -n1 -F /var/log/syslog | (while read line; do clear; echo $line | cowsay; sleep 1; done)

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
The only other way to achieve the same effect, without resorting to using a string eval, is with references and an if block of sorts, so it's definitely a bit more concise.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
There's no problem with using $@ as long the first thing you do is assign it to a lexical and then only refer to that lexical from then on. If you keep referring to $@ in your post-eval if() you run the risk of your exception handling code over-writing your exception. Also don't forget that if you're dealing with an hierarchy of exception classes you may need to test for the most specific subclass first, to ensure your handlers operate as expected:
code:
use Scalar::Util qw/blessed/;

eval {
 # Do poo poo
};

my $e = $@;

if (not blessed $e) {
  die "non-OO exception:\n" . Dumper($e);
}
elsif ( $e->isa('My::Exception::Foo::Bar') ) {
  handle_foo_bar_exception($e);
}
elsif ( $e->isa('My::Exception::Foo') ) {
  handle_foo_exception($e);
}
elsif ( $e->isa('My::Exception') ) {
   handle_exception($e);
}
Of course since you're using Moose you can use its role/metaclass methods instead of relying upon UNIVERSAL::isa;

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Where are you going to be using this user class? If I were doing it in Catalyst, for example, I'd create a new model which consumes the RDBO schemas and loads the row from the database on your behalf, before packing it into the attribute of a Moose object and returning that. Then you call high level methods on the Moose object and it operates on your RDBO row under the hood.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
You can add delegates at run-time, but you'll have to pay the toll of mutability, and to be honest database schemas don't really change all that frequently. Unless you need to do it that way, you might be best off hacking some meta-code into your toolchain so that when you update your schema files, a complete Moose role will pop out that contains a correct has 'rose' declaration, with the table's column names listed as delegates under handles. Then you can replace your existing has 'rose' declaration with, err, with.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
It does. I'm considering making a Moose-ified branch of Net::DRI, we use it pretty heavily at work and there's a lot of cruft related to validation and introspection that would be better off dead, and roles would be perfect for handling the bizarro EPP extensions that pop up at the registry and TLD levels.

(Which doesn't help at all when someone like Nominet comes along and decides to adopt the protocol for the .uk registry and then go on to ignore RFC and implement 90% of their system in the protocol's extension space, resulting in some sort of weird quantum state of simultaneously being both EPP and not-EPP and making my class hierarchy all wonky at the bottom.)

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

Fenderbender posted:

What would be the proper way to predicate or what-have-you to make it so that if the value passed to these is undef it goes to the default value?
lazy_build kinda meets your needs, although you'd need to have a custom BUILDARGS that stopped any undef attributes from reaching the constructor, otherwise either a) the undef will violate the type constraints for that attribute or b) the constraints will be too loose, allow the undef through, and the predicate will always return true, so the builder won't get called. If exists-but-undef is a valid value then you'll need to modify the attribute's operation itself...

Puck42 posted:

Is it possible to extend an object and have the extension replace one attribute with another.
code:
package User;
use Moose;

has 'name'=>(is => 'ro', isa => 'Str');

package UserManip;
extends User;
use Moose;

has '+name'=>(is => 'rw', trigger => \&change_name);

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Any mod_perl gurus around, how hard is it to dynamically configure an Apache+FastCGI vhost? I'd like to completely decouple Catalyst from our front end web servers so we can run different revisions simultaneously on the same boxes, for staging/QA, and so that we can promote a new version into production with no down-time. Mostly I'd like to be able to update the FastCGI endpoints (we're currently using TCP/IP for the back-end channel) on the fly without having to resort to writing out a new config file to disk and then reloading it.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Eurgh, that's really terrible Perl. The snippet you posted doesn't point to any obvious date attributes, so it's kinda hard to tell you how to modify it to sort by them.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
I was going to suggest checking the load_events sub to see if you could modify the query string used to retrieve events from the database, but then I took a look at some of the code from the backend and decided to go do something else

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
FindBin (part of the core) will be useful here, if the script you're trying to run is located in the same directory as your Perl:
code:
use FindBin;

my $full_path = "$FindBin::Bin/my_program";
system $full_path;

Mario Incandenza fucked around with this message at 07:34 on Nov 9, 2009

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Don't you just love it when a reference is accidentally numified and passed through to your merchant account as a $166m charge against a dummy card number and the bank locks down your payment gateway as a result? :sigh:

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Any HTML::FormHandler users around? I've got a form which is comprised of a few sub-forms which are pulled in with Moose's extends() function, and I need to make some values readonly at run-time, but the readonly() attribute for a field is => 'ro' so it blows up when passed a value, and my Moose-fu isn't yet strong enough to switch an attribute to is => 'rw' by tweaking the field's meta-class (from looking at the source for Moose::Meta::Attribute I'm not sure it's even possible).

Edit: Solved by nasty hacks.

Mario Incandenza fucked around with this message at 13:11 on Jan 6, 2010

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
http://perldoc.perl.org/perlfaq8.html#How-do-I-make-a-system()-exit-on-control-C%3f

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

Paradox posted:

Well, that's easy enough to fix. Thanks. But it's not clear to me why that has to be the case. Any thoughts?
It's because when you call system(), Perl does the equivalent of:
code:
$SIG{INT} = 'IGNORE';
So if you want your program to also catch those signals, you need to roll your own version of system() that doesn't fiddle with signal handlers.

Adbot
ADBOT LOVES YOU

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
MooseX::Types is worth looking into, if you're creating your own types there's the possibility of collisions with other packages that define the same type, whereas MX::Types prefixes all custom types with the calling package, preventing this. It also exports the short version of those names into your class via a constant sub, meaning you don't have to quote your types:

code:
use MooseX::Types::Moose qw/ Str Int /;
use Business::CreditCard ();

use MooseX::Types -declare => [qw/
  CreditCardNumber LiberalInt
/];

use Sub::Exporter -setup => { exports => [ qw/ 
  CreditCardNumber LiberalInt
/] };

subtype LiberalInt,
  as Int,
  message { "Invalid number." };

coerce LiberalInt,
  from Str,
  via {
    (my $int = $_ ) =~ s/\D+//g;
    $int
  };

subtype CreditCardNumber,
  as Str,
  where { Business::CreditCard::cardtype($_) },
  message { "Invalid card number." };

# in an HTML::FormHandler class

has_field 'card_number' => (
  type     => 'Text',
  label    => 'Credit Card number',
  apply    => [ LiberalInt, CreditCardNumber ],
  required => 1,
);

  • Locked thread