From gwadej at anomaly.org Mon Dec 5 05:29:20 2016 From: gwadej at anomaly.org (G. Wade Johnson) Date: Mon, 5 Dec 2016 07:29:20 -0600 Subject: [pm-h] December Houston.pm social meeting venue Message-ID: <20161205072920.32bf3b91@cygnus> At present, we have two contenders: - Cedar Creek Bar & Grill - 1034 w. 20th St. - Hughies Tavern and Vietnamese Grille - 1802 W. 18th Street At the moment, there seems to be a small preference for the second. If no one argues differently, I'll make a reservation (for Thursday) there tonight. G. Wade -- One of the miseries of life is that everybody names things a little bit wrong, and so it makes everything a little harder to understand in the world than it would be if it were named differently. -- Richard Feynman From gwadej at anomaly.org Tue Dec 6 18:31:55 2016 From: gwadej at anomaly.org (G. Wade Johnson) Date: Tue, 6 Dec 2016 20:31:55 -0600 Subject: [pm-h] December Houston.pm Social meeting Message-ID: <20161206203155.0cd062c5@cygnus> Based on the input so far, we'll be meeting Thursday for food and socializing at Hughies Tavern and Vietnamese Grille, 1802 W. 18th Street. (https://www.google.com/maps/place/Hughie's+Tavern+%26+Grille/@29.8012907,-95.4338512,17z/data=!4m13!1m7!3m6!1s0x8640c71c661e6af5:0x18caaa4480c77fdc!2s1802+W+18th+St,+Houston,+TX+77008!3b1!8m2!3d29.8012907!4d-95.4316625!3m4!1s0x8640c71b84de413d:0x4dbc63ac8e18293e!8m2!3d29.8014061!4d-95.4316753) Nominally, we'll be there from 7pm to 9pm. I'll try to get there earlier to reserve a table for us under my name. (They don't take reservations.) Come out for food, drink, and conversation (possibly, but not necessarily about Perl). I look forward to seeing you there. G. Wade Johnson -- You write code as if the person who will maintain your code is a violent psychopath who knows where you live. -- John F. Woods From trac_t at swbell.net Tue Dec 6 18:54:55 2016 From: trac_t at swbell.net (Trac Taylor) Date: Tue, 6 Dec 2016 20:54:55 -0600 Subject: [pm-h] December Houston.pm Social meeting In-Reply-To: <20161206203155.0cd062c5@cygnus> References: <20161206203155.0cd062c5@cygnus> Message-ID: I will be there. Thanks Wade. Trac > On Dec 6, 2016, at 8:31 PM, G. Wade Johnson via Houston wrote: > > Based on the input so far, we'll be meeting Thursday for food and > socializing at Hughies Tavern and Vietnamese Grille, 1802 W. 18th > Street. > (https://www.google.com/maps/place/Hughie's+Tavern+%26+Grille/@29.8012907,-95.4338512,17z/data=!4m13!1m7!3m6!1s0x8640c71c661e6af5:0x18caaa4480c77fdc!2s1802+W+18th+St,+Houston,+TX+77008!3b1!8m2!3d29.8012907!4d-95.4316625!3m4!1s0x8640c71b84de413d:0x4dbc63ac8e18293e!8m2!3d29.8014061!4d-95.4316753) > > Nominally, we'll be there from 7pm to 9pm. I'll try to get there > earlier to reserve a table for us under my name. (They don't take > reservations.) > > Come out for food, drink, and conversation (possibly, but not > necessarily about Perl). > > I look forward to seeing you there. > > G. Wade Johnson > -- > You write code as if the person who will maintain your code is a violent > psychopath who knows where you live. -- John F. Woods > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ From jlbprof at gmail.com Wed Dec 7 06:19:52 2016 From: jlbprof at gmail.com (Julian Brown) Date: Wed, 7 Dec 2016 08:19:52 -0600 Subject: [pm-h] December Houston.pm Social meeting In-Reply-To: References: <20161206203155.0cd062c5@cygnus> Message-ID: I will be there as well. Julian On Tue, Dec 6, 2016 at 8:54 PM, Trac Taylor via Houston wrote: > I will be there. Thanks Wade. > > Trac > > > On Dec 6, 2016, at 8:31 PM, G. Wade Johnson via Houston > wrote: > > > > Based on the input so far, we'll be meeting Thursday for food and > > socializing at Hughies Tavern and Vietnamese Grille, 1802 W. 18th > > Street. > > (https://www.google.com/maps/place/Hughie's+Tavern+%26+ > Grille/@29.8012907,-95.4338512,17z/data=!4m13!1m7! > 3m6!1s0x8640c71c661e6af5:0x18caaa4480c77fdc!2s1802+W+ > 18th+St,+Houston,+TX+77008!3b1!8m2!3d29.8012907!4d-95.4316625!3m4! > 1s0x8640c71b84de413d:0x4dbc63ac8e18293e!8m2!3d29.8014061!4d-95.4316753) > > > > Nominally, we'll be there from 7pm to 9pm. I'll try to get there > > earlier to reserve a table for us under my name. (They don't take > > reservations.) > > > > Come out for food, drink, and conversation (possibly, but not > > necessarily about Perl). > > > > I look forward to seeing you there. > > > > G. Wade Johnson > > -- > > You write code as if the person who will maintain your code is a violent > > psychopath who knows where you live. -- John F. Woods > > _______________________________________________ > > Houston mailing list > > Houston at pm.org > > http://mail.pm.org/mailman/listinfo/houston > > Website: http://houston.pm.org/ > > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at eboxr.com Thu Dec 8 11:41:27 2016 From: me at eboxr.com (Nicolas) Date: Thu, 8 Dec 2016 12:41:27 -0700 Subject: [pm-h] December Houston.pm Social meeting In-Reply-To: <20161206203155.0cd062c5@cygnus> References: <20161206203155.0cd062c5@cygnus> Message-ID: Should be able to join you for this social event :-) see you later tonight nicolas 2016-12-06 20:31 GMT-06:00 G. Wade Johnson via Houston : > Based on the input so far, we'll be meeting Thursday for food and > socializing at Hughies Tavern and Vietnamese Grille, 1802 W. 18th > Street. > (https://www.google.com/maps/place/Hughie's+Tavern+%26+ > Grille/@29.8012907,-95.4338512,17z/data=!4m13!1m7! > 3m6!1s0x8640c71c661e6af5:0x18caaa4480c77fdc!2s1802+W+ > 18th+St,+Houston,+TX+77008!3b1!8m2!3d29.8012907!4d-95.4316625!3m4! > 1s0x8640c71b84de413d:0x4dbc63ac8e18293e!8m2!3d29.8014061!4d-95.4316753) > > Nominally, we'll be there from 7pm to 9pm. I'll try to get there > earlier to reserve a table for us under my name. (They don't take > reservations.) > > Come out for food, drink, and conversation (possibly, but not > necessarily about Perl). > > I look forward to seeing you there. > > G. Wade Johnson > -- > You write code as if the person who will maintain your code is a violent > psychopath who knows where you live. -- John F. Woods > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at eboxr.com Thu Dec 8 16:57:22 2016 From: me at eboxr.com (Nicolas) Date: Fri, 09 Dec 2016 00:57:22 +0000 Subject: [pm-h] December Houston.pm Social meeting In-Reply-To: References: <20161206203155.0cd062c5@cygnus> Message-ID: The Vietnamese restaurant place is full We are moving to Spaghetti western Italian cafe 1951 w t c Jester On Thu, Dec 8, 2016 at 13:41 Nicolas wrote: > Should be able to join you for this social event :-) > see you later tonight > > nicolas > > 2016-12-06 20:31 GMT-06:00 G. Wade Johnson via Houston : > > Based on the input so far, we'll be meeting Thursday for food and > socializing at Hughies Tavern and Vietnamese Grille, 1802 W. 18th > Street. > ( > https://www.google.com/maps/place/Hughie's+Tavern+%26+Grille/@29.8012907,-95.4338512,17z/data=!4m13!1m7!3m6!1s0x8640c71c661e6af5:0x18caaa4480c77fdc!2s1802+W+18th+St,+Houston,+TX+77008!3b1!8m2!3d29.8012907!4d-95.4316625!3m4!1s0x8640c71b84de413d:0x4dbc63ac8e18293e!8m2!3d29.8014061!4d-95.4316753 > ) > > Nominally, we'll be there from 7pm to 9pm. I'll try to get there > earlier to reserve a table for us under my name. (They don't take > reservations.) > > Come out for food, drink, and conversation (possibly, but not > necessarily about Perl). > > I look forward to seeing you there. > > G. Wade Johnson > -- > You write code as if the person who will maintain your code is a violent > psychopath who knows where you live. -- John F. Woods > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlbprof at gmail.com Fri Dec 9 05:11:24 2016 From: jlbprof at gmail.com (Julian Brown) Date: Fri, 9 Dec 2016 07:11:24 -0600 Subject: [pm-h] Battlemux Message-ID: Was talking with Robert and Nicolas last night about old an old school mud. This is a telnet game that is pretty sophisticated for text, based around the FASA game Battletech. As far as I know frontierlands has the only one left still running but has hardly any attendance. http://www.sarna.net/wiki/MUX There are some graphical clients that just subsume the telnet information. I modified an existing graphical client. https://sourceforge.net/projects/thudng/?source=directory Julian -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at eboxr.com Fri Dec 9 07:31:56 2016 From: me at eboxr.com (Nicolas) Date: Fri, 9 Dec 2016 09:31:56 -0600 Subject: [pm-h] Battlemux In-Reply-To: References: Message-ID: Thanks for sharing Julian, this sounds great (cannot probably say ?looks? :-) nicolas 2016-12-09 7:11 GMT-06:00 Julian Brown via Houston : > Was talking with Robert and Nicolas last night about old an old school > mud. This is a telnet game that is pretty sophisticated for text, based > around the FASA game Battletech. > > As far as I know frontierlands has the only one left still running but has > hardly any attendance. > > http://www.sarna.net/wiki/MUX > > There are some graphical clients that just subsume the telnet information. > > I modified an existing graphical client. > > https://sourceforge.net/projects/thudng/?source=directory > > Julian > > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drzigman at drzigman.com Fri Dec 16 10:43:47 2016 From: drzigman at drzigman.com (Robert Stone) Date: Fri, 16 Dec 2016 12:43:47 -0600 Subject: [pm-h] Adventures In Getting Bitten By a Closure - Is there a better way to address this issue? Message-ID: Greetings, tl;dr - refcount unexpectedly incremented, caused DESTROY method on object to never get called. Used a workaround to address but perhaps there is a cleaner way? Jocelyn and I just spent about 3 hours tracking down why a DESTROY wasn't being called, a whole bunch of refcounts later we found the problem. I'm only fairly confident in my analysis below and would love it for any of you to chime in and say "Yep! Sounds about right" or "No way, what actually happened was..." Should be good times for all of us. For those of you who aren't fully versed on the magic that is Test::MockModule, it's the greatest thing since the circumflexion operator. It allows you to mock a method of an object and then when the variable that you assigned Test::MockModule->new to goes out of scope then the mock is removed. In general, very handy and it works perfectly. Here is the subroutine I was using to define and install my mock: sub restrict_search_space { my ( $user_ids ) = pos_validated_list( \@_, { isa => 'ArrayRef[Int]' } ); my $mocked_user = Test::MockModule->new( 'FreeChat::API::Model::User' ); $mocked_user->mock( 'search', sub { my $self = shift; my $condition = shift; my $attributes = shift // {}; $condition->{'me.id'} = { 'in' => $user_ids }; return $mocked_user->original( 'search' )->( $self, $condition, $attributes ); } ); return $mocked_user; } Seems easy enough right? I create an instance of Test::MockModule that mocks FreeChat::API::Model::User. Then I mock the search method so that I can restrict the search space by adding an additional condition to the WHERE clause that is ultimately passed down to DBIx's search method. Because what I really want here is an AROUND instead of a straight up mock I end up having to call $mocked_user->original('search') to get the original unmocked method, thereby making this into a sort of AROUND. This works no problem until you try to do something like this (actual tests! Names were not changed to protect the guilty): subtest 'Gender' => sub { my ( $mech, $user ) = get_mech_and_user(); my $male_user = create_user( gender => 'Male' ); my $female_user = create_user( gender => 'Female' ); my $mocked_user = restrict_search_space( [ $male_user->id, $female_user->id ] ); $mech->get_ok( '/users?gender=Male' ); note( 'Raw JSON Response: ' . $mech->content ); my $json = from_json( $mech->content ); ok( ( grep { $_->{id} == $male_user->id } @{$json} ), 'Matching user correctly identified' ); ok( !( grep { $_->{id} == $female_user->id } @{$json} ), 'Unmatching user correctly not identified' ); }; subtest 'Status' => sub { my ( $mech, $user ) = get_mech_and_user(); my $active_user = create_user( status => 'Active' ); my $offline_user = create_user( status => 'Offline' ); my $mocked_user = restrict_search_space( [ $active_user->id, $offline_user->id ] ); $mech->get_ok( '/users?status=Active' ); note( 'Raw JSON Response: ' . $mech->content ); my $json = from_json( $mech->content ); cmp_ok( $mech->status, '==', 200, 'Correct status' ); ok( ( grep { $_->{id} == $active_user->id } @{$json} ), 'Matching user correctly identified' ); ok( !( grep { $_->{id} == $offline_user->id } @{$json} ), 'Unmatching user correctly not identified' ); }; The first subtest passes no problem, the second one though does not. Each one does pass in isolation, but run together they fail. It fails because the instance of Test::MockModule never goes out of scope (the object pointed to by $mocked_user has a refcount of 2, not of 1) and therefore the mock never gets uninstalled. CURSES! See the issue? my $mocked_user = Test::MockModule->new( 'FreeChat::API::Model::User' ); $mocked_user->mock( 'search', sub { my $self = shift; my $condition = shift; my $attributes = shift // {}; $condition->{'me.id'} = { 'in' => $user_ids }; *return $mocked_user->original( 'search' )->( $self, $condition, $attributes );* } ); It seems that because I called $mocked_user here and have the entire thing wrapped in a sub, I'm creating a closure causing the refcount on $mocked_user to be incremented. It seems that one of the references comes from restrict_search_space's $mocked_user and the other comes from the subtest's $mocked_user. When I make the below modification: sub restrict_search_space { my ( $user_ids ) = pos_validated_list( \@_, { isa => 'ArrayRef[Int]' } ); my $mocked_user = Test::MockModule->new( 'FreeChat::API::Model::User' ); *my $original_method;* $mocked_user->mock( 'search', sub { my $self = shift; my $condition = shift; my $attributes = shift // {}; $condition->{'me.id'} = { 'in' => $user_ids }; return *$original_method*->( $self, $condition, $attributes ); } ); *$original_method = $mocked_user->original( 'search' );* return $mocked_user; } Everything worked as expected, at the end of the subtest the $mocked_user goes out of scope and the method gets unmocked. The real question, while this works it seems awfully hacky and ugly. Is there a better way to do this? Should I have used weaken somewhere? Just thought you all would enjoy commiserating with us. Hope everyone is having a safe and happy holiday. Best Regards, Robert Stone -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlbprof at gmail.com Fri Dec 16 14:40:38 2016 From: jlbprof at gmail.com (Julian Brown) Date: Fri, 16 Dec 2016 16:40:38 -0600 Subject: [pm-h] Adventures In Getting Bitten By a Closure - Is there a better way to address this issue? In-Reply-To: References: Message-ID: First of I love Test::MockModule, I am wondering if you run this on different versions of Perl if your results would be different and possibly a bug in Perl for that version? Julian On Fri, Dec 16, 2016 at 12:43 PM, Robert Stone via Houston wrote: > Greetings, > > > tl;dr - refcount unexpectedly incremented, caused DESTROY method on object > to never get called. Used a workaround to address but perhaps there is a > cleaner way? > > > Jocelyn and I just spent about 3 hours tracking down why a DESTROY wasn't > being called, a whole bunch of refcounts later we found the problem. I'm > only fairly confident in my analysis below and would love it for any of you > to chime in and say "Yep! Sounds about right" or "No way, what actually > happened was..." Should be good times for all of us. > > For those of you who aren't fully versed on the magic that is > Test::MockModule, it's the greatest thing since the circumflexion > operator. It allows you to mock a method of an object and then when the > variable that you assigned Test::MockModule->new to goes out of scope then > the mock is removed. In general, very handy and it works perfectly. > > Here is the subroutine I was using to define and install my mock: > > sub restrict_search_space { > my ( $user_ids ) = pos_validated_list( \@_, { isa => 'ArrayRef[Int]' > } ); > > my $mocked_user = Test::MockModule->new( > 'FreeChat::API::Model::User' ); > $mocked_user->mock( > 'search', > sub { > my $self = shift; > my $condition = shift; > my $attributes = shift // {}; > > $condition->{'me.id'} = { 'in' => $user_ids }; > return $mocked_user->original( 'search' )->( $self, > $condition, $attributes ); > } ); > > return $mocked_user; > } > > Seems easy enough right? I create an instance of Test::MockModule that > mocks FreeChat::API::Model::User. Then I mock the search method so that I > can restrict the search space by adding an additional condition to the > WHERE clause that is ultimately passed down to DBIx's search method. > Because what I really want here is an AROUND instead of a straight up mock > I end up having to call $mocked_user->original('search') to get the > original unmocked method, thereby making this into a sort of AROUND. > > This works no problem until you try to do something like this (actual > tests! Names were not changed to protect the guilty): > > subtest 'Gender' => sub { > my ( $mech, $user ) = get_mech_and_user(); > > my $male_user = create_user( gender => 'Male' ); > my $female_user = create_user( gender => 'Female' ); > > my $mocked_user = restrict_search_space( [ $male_user->id, > $female_user->id ] ); > > $mech->get_ok( '/users?gender=Male' ); > > note( 'Raw JSON Response: ' . $mech->content ); > my $json = from_json( $mech->content ); > > ok( ( grep { $_->{id} == $male_user->id } @{$json} ), 'Matching > user correctly identified' ); > ok( !( grep { $_->{id} == $female_user->id } @{$json} ), > 'Unmatching user correctly not identified' ); > }; > > subtest 'Status' => sub { > my ( $mech, $user ) = get_mech_and_user(); > > my $active_user = create_user( status => 'Active' ); > my $offline_user = create_user( status => 'Offline' ); > > my $mocked_user = restrict_search_space( [ $active_user->id, > $offline_user->id ] ); > > $mech->get_ok( '/users?status=Active' ); > > note( 'Raw JSON Response: ' . $mech->content ); > my $json = from_json( $mech->content ); > > cmp_ok( $mech->status, '==', 200, 'Correct status' ); > > ok( ( grep { $_->{id} == $active_user->id } @{$json} ), > 'Matching user correctly identified' ); > ok( !( grep { $_->{id} == $offline_user->id } @{$json} ), > 'Unmatching user correctly not identified' ); > }; > > The first subtest passes no problem, the second one though does not. Each > one does pass in isolation, but run together they fail. It fails because > the instance of Test::MockModule never goes out of scope (the object > pointed to by $mocked_user has a refcount of 2, not of 1) and therefore the > mock never gets uninstalled. CURSES! > > See the issue? > > my $mocked_user = Test::MockModule->new( > 'FreeChat::API::Model::User' ); > $mocked_user->mock( > 'search', > sub { > my $self = shift; > my $condition = shift; > my $attributes = shift // {}; > > $condition->{'me.id'} = { 'in' => $user_ids }; > *return $mocked_user->original( 'search' )->( $self, > $condition, $attributes );* > } ); > > It seems that because I called $mocked_user here and have the entire thing > wrapped in a sub, I'm creating a closure causing the refcount on > $mocked_user to be incremented. It seems that one of the references comes > from restrict_search_space's $mocked_user and the other comes from the > subtest's $mocked_user. When I make the below modification: > > sub restrict_search_space { > my ( $user_ids ) = pos_validated_list( \@_, { isa => 'ArrayRef[Int]' > } ); > > my $mocked_user = Test::MockModule->new( > 'FreeChat::API::Model::User' ); > *my $original_method;* > $mocked_user->mock( > 'search', > sub { > my $self = shift; > my $condition = shift; > my $attributes = shift // {}; > > $condition->{'me.id'} = { 'in' => $user_ids }; > return *$original_method*->( $self, $condition, $attributes > ); > } ); > > *$original_method = $mocked_user->original( 'search' );* > > return $mocked_user; > } > > Everything worked as expected, at the end of the subtest the $mocked_user > goes out of scope and the method gets unmocked. > > The real question, while this works it seems awfully hacky and ugly. Is > there a better way to do this? Should I have used weaken somewhere? > > Just thought you all would enjoy commiserating with us. Hope everyone is > having a safe and happy holiday. > > Best Regards, > Robert Stone > > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drzigman at drzigman.com Fri Dec 16 14:51:46 2016 From: drzigman at drzigman.com (Robert Stone) Date: Fri, 16 Dec 2016 16:51:46 -0600 Subject: [pm-h] Adventures In Getting Bitten By a Closure - Is there a better way to address this issue? In-Reply-To: References: Message-ID: Greetings, Tried in 5.16.3 and 5.24.0. One of our debugging steps was to take advantage of perlbrew and try it in a different version of perl. Same result. Interesting idea that this could be a perl bug. I don't know if I'd call this a bug though, as much as perl doing *exactly* what you asked it to without knowing what you were asking. Best Regards, Robert Stone On Fri, Dec 16, 2016 at 4:40 PM, Julian Brown via Houston wrote: > First of I love Test::MockModule, > > I am wondering if you run this on different versions of Perl if your > results would be different and possibly a bug in Perl for that version? > > Julian > > On Fri, Dec 16, 2016 at 12:43 PM, Robert Stone via Houston > wrote: > >> Greetings, >> >> >> tl;dr - refcount unexpectedly incremented, caused DESTROY method on >> object to never get called. Used a workaround to address but perhaps there >> is a cleaner way? >> >> >> Jocelyn and I just spent about 3 hours tracking down why a DESTROY wasn't >> being called, a whole bunch of refcounts later we found the problem. I'm >> only fairly confident in my analysis below and would love it for any of you >> to chime in and say "Yep! Sounds about right" or "No way, what actually >> happened was..." Should be good times for all of us. >> >> For those of you who aren't fully versed on the magic that is >> Test::MockModule, it's the greatest thing since the circumflexion >> operator. It allows you to mock a method of an object and then when the >> variable that you assigned Test::MockModule->new to goes out of scope then >> the mock is removed. In general, very handy and it works perfectly. >> >> Here is the subroutine I was using to define and install my mock: >> >> sub restrict_search_space { >> my ( $user_ids ) = pos_validated_list( \@_, { isa => >> 'ArrayRef[Int]' } ); >> >> my $mocked_user = Test::MockModule->new( >> 'FreeChat::API::Model::User' ); >> $mocked_user->mock( >> 'search', >> sub { >> my $self = shift; >> my $condition = shift; >> my $attributes = shift // {}; >> >> $condition->{'me.id'} = { 'in' => $user_ids }; >> return $mocked_user->original( 'search' )->( $self, >> $condition, $attributes ); >> } ); >> >> return $mocked_user; >> } >> >> Seems easy enough right? I create an instance of Test::MockModule that >> mocks FreeChat::API::Model::User. Then I mock the search method so that I >> can restrict the search space by adding an additional condition to the >> WHERE clause that is ultimately passed down to DBIx's search method. >> Because what I really want here is an AROUND instead of a straight up mock >> I end up having to call $mocked_user->original('search') to get the >> original unmocked method, thereby making this into a sort of AROUND. >> >> This works no problem until you try to do something like this (actual >> tests! Names were not changed to protect the guilty): >> >> subtest 'Gender' => sub { >> my ( $mech, $user ) = get_mech_and_user(); >> >> my $male_user = create_user( gender => 'Male' ); >> my $female_user = create_user( gender => 'Female' ); >> >> my $mocked_user = restrict_search_space( [ $male_user->id, >> $female_user->id ] ); >> >> $mech->get_ok( '/users?gender=Male' ); >> >> note( 'Raw JSON Response: ' . $mech->content ); >> my $json = from_json( $mech->content ); >> >> ok( ( grep { $_->{id} == $male_user->id } @{$json} ), 'Matching >> user correctly identified' ); >> ok( !( grep { $_->{id} == $female_user->id } @{$json} ), >> 'Unmatching user correctly not identified' ); >> }; >> >> subtest 'Status' => sub { >> my ( $mech, $user ) = get_mech_and_user(); >> >> my $active_user = create_user( status => 'Active' ); >> my $offline_user = create_user( status => 'Offline' ); >> >> my $mocked_user = restrict_search_space( [ $active_user->id, >> $offline_user->id ] ); >> >> $mech->get_ok( '/users?status=Active' ); >> >> note( 'Raw JSON Response: ' . $mech->content ); >> my $json = from_json( $mech->content ); >> >> cmp_ok( $mech->status, '==', 200, 'Correct status' ); >> >> ok( ( grep { $_->{id} == $active_user->id } @{$json} ), >> 'Matching user correctly identified' ); >> ok( !( grep { $_->{id} == $offline_user->id } @{$json} ), >> 'Unmatching user correctly not identified' ); >> }; >> >> The first subtest passes no problem, the second one though does not. >> Each one does pass in isolation, but run together they fail. It fails >> because the instance of Test::MockModule never goes out of scope (the >> object pointed to by $mocked_user has a refcount of 2, not of 1) and >> therefore the mock never gets uninstalled. CURSES! >> >> See the issue? >> >> my $mocked_user = Test::MockModule->new( >> 'FreeChat::API::Model::User' ); >> $mocked_user->mock( >> 'search', >> sub { >> my $self = shift; >> my $condition = shift; >> my $attributes = shift // {}; >> >> $condition->{'me.id'} = { 'in' => $user_ids }; >> *return $mocked_user->original( 'search' )->( $self, >> $condition, $attributes );* >> } ); >> >> It seems that because I called $mocked_user here and have the entire >> thing wrapped in a sub, I'm creating a closure causing the refcount on >> $mocked_user to be incremented. It seems that one of the references comes >> from restrict_search_space's $mocked_user and the other comes from the >> subtest's $mocked_user. When I make the below modification: >> >> sub restrict_search_space { >> my ( $user_ids ) = pos_validated_list( \@_, { isa => >> 'ArrayRef[Int]' } ); >> >> my $mocked_user = Test::MockModule->new( >> 'FreeChat::API::Model::User' ); >> *my $original_method;* >> $mocked_user->mock( >> 'search', >> sub { >> my $self = shift; >> my $condition = shift; >> my $attributes = shift // {}; >> >> $condition->{'me.id'} = { 'in' => $user_ids }; >> return *$original_method*->( $self, $condition, >> $attributes ); >> } ); >> >> *$original_method = $mocked_user->original( 'search' );* >> >> return $mocked_user; >> } >> >> Everything worked as expected, at the end of the subtest the $mocked_user >> goes out of scope and the method gets unmocked. >> >> The real question, while this works it seems awfully hacky and ugly. Is >> there a better way to do this? Should I have used weaken somewhere? >> >> Just thought you all would enjoy commiserating with us. Hope everyone is >> having a safe and happy holiday. >> >> Best Regards, >> Robert Stone >> >> _______________________________________________ >> Houston mailing list >> Houston at pm.org >> http://mail.pm.org/mailman/listinfo/houston >> Website: http://houston.pm.org/ >> > > > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gwadej at anomaly.org Sun Dec 18 08:57:16 2016 From: gwadej at anomaly.org (G. Wade Johnson) Date: Sun, 18 Dec 2016 10:57:16 -0600 Subject: [pm-h] Adventures In Getting Bitten By a Closure - Is there a better way to address this issue? In-Reply-To: References: Message-ID: <20161218105716.7a659890@cygnus> Unfortunately, Perl did exactly what you told it to do. Closures do make a new reference to the object that does not exactly go away in the case you are showing. You should be able to solve the problem differently with Scalar::Util::weaken, which explicitly reduces the reference count. The only advantage of weaken is the fact that it is explicit and might not be subject to later "correction" of something that seems redundant. G. Wade On Fri, 16 Dec 2016 16:51:46 -0600 Robert Stone via Houston wrote: > Greetings, > > Tried in 5.16.3 and 5.24.0. One of our debugging steps was to take > advantage of perlbrew and try it in a different version of perl. Same > result. > > Interesting idea that this could be a perl bug. I don't know if I'd > call this a bug though, as much as perl doing *exactly* what you > asked it to without knowing what you were asking. > > Best Regards, > Robert Stone > > On Fri, Dec 16, 2016 at 4:40 PM, Julian Brown via Houston > wrote: > > > First of I love Test::MockModule, > > > > I am wondering if you run this on different versions of Perl if your > > results would be different and possibly a bug in Perl for that > > version? > > > > Julian > > > > On Fri, Dec 16, 2016 at 12:43 PM, Robert Stone via Houston > > > > wrote: > > > >> Greetings, > >> > >> > >> tl;dr - refcount unexpectedly incremented, caused DESTROY method on > >> object to never get called. Used a workaround to address but > >> perhaps there is a cleaner way? > >> > >> > >> Jocelyn and I just spent about 3 hours tracking down why a DESTROY > >> wasn't being called, a whole bunch of refcounts later we found the > >> problem. I'm only fairly confident in my analysis below and would > >> love it for any of you to chime in and say "Yep! Sounds about > >> right" or "No way, what actually happened was..." Should be good > >> times for all of us. > >> > >> For those of you who aren't fully versed on the magic that is > >> Test::MockModule, it's the greatest thing since the circumflexion > >> operator. It allows you to mock a method of an object and then > >> when the variable that you assigned Test::MockModule->new to goes > >> out of scope then the mock is removed. In general, very handy and > >> it works perfectly. > >> > >> Here is the subroutine I was using to define and install my mock: > >> > >> sub restrict_search_space { > >> my ( $user_ids ) = pos_validated_list( \@_, { isa => > >> 'ArrayRef[Int]' } ); > >> > >> my $mocked_user = Test::MockModule->new( > >> 'FreeChat::API::Model::User' ); > >> $mocked_user->mock( > >> 'search', > >> sub { > >> my $self = shift; > >> my $condition = shift; > >> my $attributes = shift // {}; > >> > >> $condition->{'me.id'} = { 'in' => $user_ids }; > >> return $mocked_user->original( 'search' )->( $self, > >> $condition, $attributes ); > >> } ); > >> > >> return $mocked_user; > >> } > >> > >> Seems easy enough right? I create an instance of Test::MockModule > >> that mocks FreeChat::API::Model::User. Then I mock the search > >> method so that I can restrict the search space by adding an > >> additional condition to the WHERE clause that is ultimately passed > >> down to DBIx's search method. Because what I really want here is > >> an AROUND instead of a straight up mock I end up having to call > >> $mocked_user->original('search') to get the original unmocked > >> method, thereby making this into a sort of AROUND. > >> > >> This works no problem until you try to do something like this > >> (actual tests! Names were not changed to protect the guilty): > >> > >> subtest 'Gender' => sub { > >> my ( $mech, $user ) = get_mech_and_user(); > >> > >> my $male_user = create_user( gender => 'Male' ); > >> my $female_user = create_user( gender => 'Female' ); > >> > >> my $mocked_user = > >> restrict_search_space( [ $male_user->id, $female_user->id ] ); > >> > >> $mech->get_ok( '/users?gender=Male' ); > >> > >> note( 'Raw JSON Response: ' . $mech->content ); > >> my $json = from_json( $mech->content ); > >> > >> ok( ( grep { $_->{id} == $male_user->id } @{$json} ), > >> 'Matching user correctly identified' ); > >> ok( !( grep { $_->{id} == $female_user->id } @{$json} ), > >> 'Unmatching user correctly not identified' ); > >> }; > >> > >> subtest 'Status' => sub { > >> my ( $mech, $user ) = get_mech_and_user(); > >> > >> my $active_user = create_user( status => 'Active' ); > >> my $offline_user = create_user( status => 'Offline' ); > >> > >> my $mocked_user = > >> restrict_search_space( [ $active_user->id, $offline_user->id ] ); > >> > >> $mech->get_ok( '/users?status=Active' ); > >> > >> note( 'Raw JSON Response: ' . $mech->content ); > >> my $json = from_json( $mech->content ); > >> > >> cmp_ok( $mech->status, '==', 200, 'Correct status' ); > >> > >> ok( ( grep { $_->{id} == $active_user->id } @{$json} ), > >> 'Matching user correctly identified' ); > >> ok( !( grep { $_->{id} == $offline_user->id } @{$json} ), > >> 'Unmatching user correctly not identified' ); > >> }; > >> > >> The first subtest passes no problem, the second one though does > >> not. Each one does pass in isolation, but run together they fail. > >> It fails because the instance of Test::MockModule never goes out > >> of scope (the object pointed to by $mocked_user has a refcount of > >> 2, not of 1) and therefore the mock never gets uninstalled. > >> CURSES! > >> > >> See the issue? > >> > >> my $mocked_user = Test::MockModule->new( > >> 'FreeChat::API::Model::User' ); > >> $mocked_user->mock( > >> 'search', > >> sub { > >> my $self = shift; > >> my $condition = shift; > >> my $attributes = shift // {}; > >> > >> $condition->{'me.id'} = { 'in' => $user_ids }; > >> *return $mocked_user->original( 'search' )->( $self, > >> $condition, $attributes );* > >> } ); > >> > >> It seems that because I called $mocked_user here and have the > >> entire thing wrapped in a sub, I'm creating a closure causing the > >> refcount on $mocked_user to be incremented. It seems that one of > >> the references comes from restrict_search_space's $mocked_user and > >> the other comes from the subtest's $mocked_user. When I make the > >> below modification: > >> > >> sub restrict_search_space { > >> my ( $user_ids ) = pos_validated_list( \@_, { isa => > >> 'ArrayRef[Int]' } ); > >> > >> my $mocked_user = Test::MockModule->new( > >> 'FreeChat::API::Model::User' ); > >> *my $original_method;* > >> $mocked_user->mock( > >> 'search', > >> sub { > >> my $self = shift; > >> my $condition = shift; > >> my $attributes = shift // {}; > >> > >> $condition->{'me.id'} = { 'in' => $user_ids }; > >> return *$original_method*->( $self, $condition, > >> $attributes ); > >> } ); > >> > >> *$original_method = $mocked_user->original( 'search' );* > >> > >> return $mocked_user; > >> } > >> > >> Everything worked as expected, at the end of the subtest the > >> $mocked_user goes out of scope and the method gets unmocked. > >> > >> The real question, while this works it seems awfully hacky and > >> ugly. Is there a better way to do this? Should I have used > >> weaken somewhere? > >> > >> Just thought you all would enjoy commiserating with us. Hope > >> everyone is having a safe and happy holiday. > >> > >> Best Regards, > >> Robert Stone > >> > >> _______________________________________________ > >> Houston mailing list > >> Houston at pm.org > >> http://mail.pm.org/mailman/listinfo/houston > >> Website: http://houston.pm.org/ > >> > > > > > > _______________________________________________ > > Houston mailing list > > Houston at pm.org > > http://mail.pm.org/mailman/listinfo/houston > > Website: http://houston.pm.org/ > > -- The purpose of software engineering is to control complexity, not to create it. -- Dr. Pamela Zave From gwadej at anomaly.org Fri Dec 30 05:34:51 2016 From: gwadej at anomaly.org (G. Wade Johnson) Date: Fri, 30 Dec 2016 07:34:51 -0600 Subject: [pm-h] Topic for January Message-ID: <20161230073451.46fa1073@cygnus> We still don't have a topic for the January 12 meeting at cPanel. Is everyone worn out from the holidays? Surely someone has a topic of interest. How about lightning talks? If we could get 4-8 people to volunteer to give a 5 minute talk on a technique or module, we'd have a meeting. Discussion topic? Would someone like to propose a topic that they would like to have the group discuss rather than just have one person present? Looking forward to hearing your ideas. G. Wade -- You write code as if the person who will maintain your code is a violent psychopath who knows where you live. -- John F. Woods From drzigman at drzigman.com Fri Dec 30 13:30:15 2016 From: drzigman at drzigman.com (Robert Stone) Date: Fri, 30 Dec 2016 15:30:15 -0600 Subject: [pm-h] Topic for January In-Reply-To: <20161230073451.46fa1073@cygnus> References: <20161230073451.46fa1073@cygnus> Message-ID: Greetings, I think lightening talks could be a great idea to ease us back in after the holidays. I've been doing some C# work (gasp) and working with WPF (double gasp) while creating a nifty desktop switcher for windows (triple gasp!). Would love to show it off and hear what everyone else has been working on over the break. Friendly reminder that lightening talks are a *fantastic* way to get your feet wet in terms of being a presenter. If anyone has been hesitant to put together something before, this is an excellent opportunity for you. Best Regards, Robert Stone On Fri, Dec 30, 2016 at 7:34 AM, G. Wade Johnson via Houston wrote: > We still don't have a topic for the January 12 meeting at cPanel. > > Is everyone worn out from the holidays? Surely someone has a topic of > interest. > > How about lightning talks? If we could get 4-8 people to volunteer to > give a 5 minute talk on a technique or module, we'd have a meeting. > > Discussion topic? Would someone like to propose a topic that they would > like to have the group discuss rather than just have one person present? > > Looking forward to hearing your ideas. > G. Wade > -- > You write code as if the person who will maintain your code is a violent > psychopath who knows where you live. -- John F. Woods > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reini.urban at gmail.com Fri Dec 30 13:33:43 2016 From: reini.urban at gmail.com (Reini Urban) Date: Fri, 30 Dec 2016 22:33:43 +0100 Subject: [pm-h] Topic for January In-Reply-To: <20161230073451.46fa1073@cygnus> References: <20161230073451.46fa1073@cygnus> Message-ID: I could give a talk about our cpanel fork of perl, cperl. But I'm in late January only, 20-27 Am 30.12.2016 2:36 nachm. schrieb "G. Wade Johnson via Houston" < houston at pm.org>: > We still don't have a topic for the January 12 meeting at cPanel. > > Is everyone worn out from the holidays? Surely someone has a topic of > interest. > > How about lightning talks? If we could get 4-8 people to volunteer to > give a 5 minute talk on a technique or module, we'd have a meeting. > > Discussion topic? Would someone like to propose a topic that they would > like to have the group discuss rather than just have one person present? > > Looking forward to hearing your ideas. > G. Wade > -- > You write code as if the person who will maintain your code is a violent > psychopath who knows where you live. -- John F. Woods > _______________________________________________ > Houston mailing list > Houston at pm.org > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: