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
leedo
Nov 28, 2000

Not exactly a question, but I thought someone might get a kick out of it...

Here is a horrible "IMAP to Google Calendar" program that I wrote last night. I thought it might help me in filling out my time sheets at work. Turns out that it is completely useless!

Adbot
ADBOT LOVES YOU

leedo
Nov 28, 2000

Satan's Scallion posted:

You may want to remove your login and password from that...

God damnit, why do I always do stupid poo poo like this late at night. :(

leedo
Nov 28, 2000

syphon^2 posted:

1) I'm not too knowledgable on mod_perl, but I installed it and tried it out. I think the big thing is that CGI loads the Perl interpreter independently with each call to a CGI page, while mod_perl keeps it loaded and just serves the page at request. It saves CPU cycles and makes the app run faster.
In addition to that, mod_perl also gives you access to the entire apache request cycle. This lets you do things like URL rewriting with perl. You can also configure Apache itself with mod_perl, which I have found to be a godsend for setting up shared hosting environments.

quote:

2) Catalyst is a pretty big framework. Personally, I found the overhead to be HUGE. I'd use this if I were developing some HUGE perl web-app, but otherwise, I'd avoid it. I installed it and played around, and after a few hours, I was still really far from actually getting anything done.
Granted Catalyst has a lot of dependencies, but just like any other framework once you pick it up you'll be able to pump out web apps much faster.

I agree that starting with plain CGI scripting is best, simply so you can learn why frameworks like Catalyst exist.

leedo
Nov 28, 2000

mister_gosh posted:

I have a question. I have a filehandle I'm printing to:

code:
open(OUT, ">C:/example.txt");
...
print OUT "something";
...
close OUT
If someone CTRL-C's this script, nothing gets put in to C:/example.txt. Is there a way to ensure it closes properly or a better way of doing this?

Edit: thinking about this some more, is there a way to do something like if a user does CTRL-C or if there is an abrupt end or big error, can the program say "on exit, close this file handle?"

I've never had to do it, but you could try something like:
code:
open(my $out, '>', 'C:/example.txt');
$SIG{INT} = sub { close $out; };
print $out "something";
close $out;
Regarding autoflush I would probably do it this way, for the sake of whoever is going to be maintaining the code:
code:
use constant { TRUE => 1, FALSE => 0 };
$OUTPUT_AUTOFLUSH = TRUE;
edit: bleh beaten...

leedo fucked around with this message at 22:37 on Dec 7, 2007

leedo
Nov 28, 2000

I haven't really been following perl6 too closely, but I am excited to see him write about including multiple dispatch and some form of typing.

leedo
Nov 28, 2000

mister_gosh posted:

What does the extra dollar sign mean in a variable?

For example: $$variableName

That would dereference a reference to a scalar. Example:
code:
my $foo = "uhh";
my $bar = \$foo;
print $$bar; #prints "uhh"

leedo
Nov 28, 2000

more falafel please posted:

All I know about Catalyst is that I went to school with the author of this book and he's the crazy shut-in nerd type who's so much smarter than you or any of his professors that he doesn't need to do his work because it's below him, which is why going to school is dumb and they SHOULD just kick him out for failing all his classes.
Well, I know he at least gets out for the local Perl Mongers meetings. I think he is in charge of organizing YAPC'08 as well.

leedo
Nov 28, 2000

SpeedFrog posted:

code:
# matches [url]http://dev.blah.com/login/submit[/url]
sub submit :Local {
  my ($self, $c) = @_;

  my $q = $c->req->params;

  if ($c->login([b]@$q{qw/username password/}[/b])) {
    $c->stash->{success} = 1;
  }
  else {
    $c->stash->{success} = undef;
    $c->stash->{errors} = { username => 'bad login details.', password => 'bad login details.' };
  }

  $c->detach('View::JSON');
}
Whoa, I had never seen that syntax before (using a list of hash keys)... cool!

leedo
Nov 28, 2000

I use constant.pm in most of my perl programs; though usually only to define TRUE and FALSE.

leedo
Nov 28, 2000

I'm going to be there on and off throughout. My work isn't paying for it so I am taking a few half days to see the talks I am interested in.

leedo
Nov 28, 2000

Is there any way to have a method detect the context it is being called in (list or scalar)? Right now I am returning a ton of arrayrefs in a module I am working on, but would like to return a list in list context. DBIx::Class seems to do this with it's ResultSets but I can't seem to see how.

Ideally it could do this:
code:
my $artists = $obj->search('ween'); # returns an arrayref

for my $artist ($obj->search('ween')) { } #returns an array
edit: annnnd I quickly answered my own question with
code:
perldoc -f wantarray

leedo fucked around with this message at 01:20 on Aug 27, 2008

leedo
Nov 28, 2000

heeen posted:

I've seen this:
code:
sub getStuff()
{
my @foo;
.
.
.
return wantarray? @foo : \@foo;
}

This is essentially what I'm doing, though I'm tempted to just always return the array.

leedo
Nov 28, 2000

uG posted:

How can I install the Moose branch of Catalyst 5.80 using cpan? :(

I don't think that is possible. You would probably have to do an svn checkout and install that way. I don't really see the point in doing that, I can't imagine much is changing on the userspace end of things.

edit: speaking of which, there was a good interview with mst about Catamoose today
http://jjnapiorkowski.vox.com/library/post/catamoose-part-two-mst-speaks.html

leedo fucked around with this message at 21:25 on Sep 8, 2008

leedo
Nov 28, 2000

SpeedFrog posted:

Yup, that works just fine, in fact I believe that's the recommended place, as it sits nicely alongside your relationship definitions (you mean resultset_class('Game::DB::ResultSet::Table'), yeah?).

Also, I know it's in the docs, but it's useful enough to bear repeating... if you ever need a plain hashref, you can do this (though keep in mind the keys still will be lowercased):

code:
my $rs = MyDB::Schema::Database->resultset('Table');
my $inflator = 'DBIx::ResultClass::HashRefInflator';

eval "require $inflator";
$rs->result_class($inflator);

while (my $hashref = $rs->next) {
}
Hmm, never knew about the built in conversion to hashref. I always just wrote my own methods in the Schema. Does HashRefInflator follow foreign keys and hashref-ize the referenced objects?

leedo
Nov 28, 2000

This seems more clear, but I guess it is probably slower:
code:
my $string = "lolol";
print "palindrome" if $string eq join '', split //, reverse $string;
edit: vvv I have a rare talent for not reading instructions

leedo fucked around with this message at 21:27 on Nov 14, 2008

leedo
Nov 28, 2000

Whelp, i suck :(

leedo
Nov 28, 2000

Has anyone else been playing around with perl6 the past few weeks?

I started writing a console version of Risk in p6, and was very surprised by how much is working. I got most of the classes set up with the appropriate properties and methods, and it all compiles cleanly.

Right now I am putting off figuring out the best way to draw a undirected graph to the console. Does anyone know of a good example I can go off of? I did a few searches on CPAN and found very little.

leedo fucked around with this message at 20:34 on Jan 4, 2009

leedo
Nov 28, 2000

SpeedFrog posted:

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.

That is perfect, thanks! Should give me something to do for the next few weeks.

leedo
Nov 28, 2000

I don't think it gets much cheaper than YAPC. I paid for it out of pocket last year when it was in Chicago. Well worth it, IMO.

leedo
Nov 28, 2000

Welp, I just got a new job doing full time perl development, so expect more embarrassing code snippets from me soon!

leedo
Nov 28, 2000

Triple Tech posted:

Congratulations. What city are you in?

I'm in Chicago. I've actually been seeing quite a few (3-4 a month) Chicago perl jobs showing up jobs.perl.org.

leedo
Nov 28, 2000

I'm starting a new project at work and I am looking for a web framework with a more lightweight install than Catalyst. I have a lot of experience with Catalyst, and it would actually work really well for this, but I'm afraid the massive list of CPAN dependencies will scare away the higher-ups.

I'm looking at CGI::Application right now. I have a rather large DBIx::Class schema, so it is nice that it can be used as a mod_perl handler (presumably not reloading the schema on each request.)

Any other suggestions? The trend around here has been to roll their own frameworks, but hopefully I can steer them in the direction of Catalyst eventually.

edit: on second thought, gently caress it, all the Catalyst modules I need are in Debian already so the install is not going to be painful.

leedo fucked around with this message at 02:09 on Apr 21, 2009

leedo
Nov 28, 2000

YAPC tickets are on sale at a big discount this week. I picked some up, though I'm not 100% sure I can make it. At the very least it is a decent donation.

http://yapc10.org/yn2009/

leedo
Nov 28, 2000

atomicstack posted:

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!

I think this will be the impetus to get me to finally start using Moose. Cool!

leedo
Nov 28, 2000

dagard posted:

I've been using Catalyst lately for an internal project (inventory tracking for my group of system administrators), and while I love it, I seem to be google-blind on one thing. Query caching.

Example: You're looking at an audit page, where you see the last 30 changes. Each row of the audit log is generating another hit against the 'users' table to pull out username, display name, email address, etc.

Ideally, I'd like something that, either in Catalyst or TT2, I can go 'ok, for this page, this render, cache everything'

Would I have to roll my own? (doable), or is there something I'm just too blind to see?

I haven't done much with it, but you could use Catalyst::Plugin::Cache. An example could look something like this (taken straight from the docs):
code:
unless ($user_data = $c->cache->get($user_id) ) {
  $user_data = $c->model('MyApp::User')->find($user_id);
   $c->cache->set( $user_id, $user_data );
}
And then clear the cache at the end of the request.

leedo
Nov 28, 2000

I have been super bored this weekend and started working on an Gtk+ irc client in perl. My main goal is to be compatible with Colloquy styles, which consist of html, css, and an xslt file. I am using WebKit for the HTML view, which is also what Colloquy uses. It is pretty neat, because there is a great Colloquy style that can do inline images, as well as inline audio (via the <audio> element.)

Here is a large screenshot

I've got everything working, but now I am going back and re-writing it with Moose. It is a bit of a pain, but I can already see it becoming more readable and easier to update.

leedo
Nov 28, 2000

I recently used DBIx::Class to define a fairly complex schema (~20 tables, each with 2-5 relationships), and it worked out really well. I wrote the entire schema in Perl first and used the create_ddl_dir method to export it out the SQL schema. This way I could export out very basic SQL for SQLite on my local machine, and SQL with the constraints supported by MySQL in production. It also handles diffs between schema revisions, so I could easily upgrade a DB without wiping everything out.

I also really enjoy not having to write out queries by hand, but that speaks more to my dislike of writing SQL than anything else.

leedo
Nov 28, 2000

Scentaur posted:

perl n00b question for ya'll

finishing up my first class in perl and its def become my fav. There is an optional project that i want to do and am looking for some ideas. its pretty open ended, basically just need to write a nifty lil cgi/perl script that hasn't been covered in class.

im NOT trying to weasel my way into someone doing this for me! just lookin for a few ideas or a point in the right direction for something cool i can put together. we've done basic stuff like cookies, redirection, form validation, sendmail etc so maybe something along that experience level?

any thoughts would be much appreciated thx

I'd suggest choosing something you are already interested in. Do you like music? If so take a look at the last.fm API and try doing something with that. Whatever you are interested in there is probably a CPAN module that deals with it, which you could then tie together in a CGI script.

leedo
Nov 28, 2000

Mithaldu posted:

I'm currently trying to figure out a performance issue i have when splitting a CSV file into arrays of arrays. The first run through a file is pretty fast. However EVERY run after that is very slow.

...

Any suggestions as to how this could be caused and how i can avoid it? (Suggestions as to who i could ask about this other than Perlmonks would be neat too.)

While I can't tell you what is causing the slowdown, I can heartily recommend using Text::CSV_XS for any CSV processing.

leedo
Nov 28, 2000

Sartak posted:

The YAPC::NA schedule was just published. My "Extending Moose for Applications" talk was accepted :toot:

It's at 8am though.

Anyone planning on going? It's in Pittsburgh, June 22-24.

I'm going to be at YAPC::NA, I'll try to check it out. I am probably most interested in the Moose and Perl 6 talks.

leedo
Nov 28, 2000

Triple Tech posted:

I see that YAPC is quickly approaching... So I guess I will attend and see if my company will reimburse me after the fact. I'll just use up all my vacation days and check out sunny Pittsburg! Ugh...

How much of this bitch can I put on credit... And I guess now it's a great time to look into an Apple laptop. Can't do mobile hacking without one, right?

Edit: Gorsh, this poo poo is expensive. Are you guys going for like all the days, Thursday, Friday, Sunday?

I'm just doing Monday - Wednesday, it doesn't look like too much is going on the rest of the week. And it was only 99 dollars if you ordered tickets a month or so ago, I can't think of a cheaper conference! :)

leedo
Nov 28, 2000

Sartak posted:

Miyagawa has written a quick blog post about building native OS X applications out of Perl programs and their dependencies. It uses Platypus to do the heavy lifting.

http://remediecode.org/2009/06/binary-builds-for-os-x-leopard-users.html

I'm pretty excited by this, and hope it eventually becomes as easy to package up apps for Windows and Linux.

Wow, that was really awesome. I just built an .app in 5 minutes for my latest waste of time:

http://github.com/leedo/buttesfire-web/tree/master

It launches a POE::IRC client and lets you interact with it using Safari or FF. It uses long polling to stream the data to the browsers. The great part is that most of the client development is done on the javascript side, so I can just refresh the browser to test out new things, no need to reconnect. (Yes I recreated CGI::IRC, ok)

leedo fucked around with this message at 06:59 on Jun 16, 2009

leedo
Nov 28, 2000

I came in in for the end of the most recent Git talk. it seems like things are really running behind schedule, unless I'm reading things wrong. They cut off the Perl 6 regex talk before he finished, but the Git talk went like 15 minutes over.

Anyways, I'm sticking around for the next Git talk. I'm bearded and in a plain white t-shirt and jeans.

leedo
Nov 28, 2000

Triple Tech posted:

That describes no one. Are you on IRC or something?

I am! I just joined #yapc as "lee_" which appears looks pretty full.

edit: i think i'm going to head over to the mod_perl6 talk, though. It seems like they skipped one of the git talks, but more likely I am just very confused.

leedo fucked around with this message at 20:39 on Jun 22, 2009

leedo
Nov 28, 2000

Did anyone else get sick from that dinner last night? I woke up with horrible stomach pain and a fever this morning. Now I am just hoping I don't puke on this flight back to Chicago. Not a great way to end the trip :(

leedo
Nov 28, 2000

The IRC bot talk a few posts back reminded me to upload this IRC HTML formatting module I have been sitting on. So if you every need to export raw IRC to HTML give it a try!

http://search.cpan.org/~leedo/IRC-Formatting-HTML-0.01/

leedo
Nov 28, 2000

Ok, so here is a potentially stupid Moose question.

I have a class that has a "config" property, and a "server" property. The creation of the server property requires that the config property be set so that I can use some of the config fields when setting up the server. Normally I would just set the server property to lazy like so:
code:
has => 'config' => (
  is => 'ro',
  isa => 'HashRef',
  required => 1,
);

has => 'server' => (
  is => ro,
  isa => 'HTTPD::Server',
  lazy => 1,
  default => sub {
    # build server with access to $self->config
  }
);
The problem here is that I need server to be built at initialization, not lazily. But, if I set server to not be lazy config is not defined yet. I tried using a builder but it still seems to fire off before config is defined.

Do I need to move this into a BUILD sub? Or is there some way to specify the order that properties are defined?

edit: I got this working by setting the server in a trigger on config. Still not sure if that is the best approach, though.

leedo fucked around with this message at 23:21 on Jul 30, 2009

leedo
Nov 28, 2000

Mithaldu posted:

^^^^
Thanks. :)
Huh, i didn't even consider it in that way or rather, didn't know of exists before today.

When would i want to use exists specifically versus undefined? I understand the difference in what it does, but not the practical use.

defined will autovivify the hash element, where as exists will not. At least that is how I always understood it.

leedo
Nov 28, 2000

Sartak posted:

No, autovivification happens when you access a deep structure.

return $a{b}{c};

That autovivifies $a{b} to be a hashref, even if %a was empty.

You care about defined versus exists when undef is a valid value. For example, when your attribute can contain any Perl value (including undef) and you need to know when the attribute has a value or not, then you use exists.

Wow, I could have sworn defined would create the hash key. But yeah I just did a little test and you're definitely right.

Adbot
ADBOT LOVES YOU

leedo
Nov 28, 2000

Mario Incandenza posted:

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:

Haha. The catalyst app that I wrote for CC processing successfully charged a card for 20k recently. I guess they actually owed us that much, but we're supposed to get paid by money order for anything that large. Oops, guess I should add an upper limit :o

  • Locked thread