Skip to content
Browse files

moves save_token into its own role

  • Loading branch information...
1 parent 1dc7d64 commit 87345945552b9a61d3eea21e5577692dd376fd0c @spazm committed
Showing with 43 additions and 30 deletions.
  1. +5 −27 lib/Facebook/Graph/Cmdline.pm
  2. +0 −3 lib/Facebook/Graph/role/HTTPtoken.pm
  3. +38 −0 lib/Facebook/Graph/role/save_token.pm
View
32 lib/Facebook/Graph/Cmdline.pm
@@ -7,10 +7,12 @@ use v5.10;
extends 'Facebook::Graph';
with 'Facebook::Graph::role::HTTPtoken';
+
#Is there a better way to do MooseX vs MouseX 'with' loading?
#can import with "use Any::Moose 'X::SimpleConfig'" but that doesn't
#provide the action of "with," Mo*se::Util::apply_all_roles()
-if (Any::Moose::moose_is_preferred) {
+if (Any::Moose::moose_is_preferred)
+{
with 'MooseX::SimpleConfig';
with 'MooseX::Getopt';
}
@@ -19,32 +21,8 @@ else
with 'MouseX::SimpleConfig';
with 'MouseX::Getopt';
}
-
-=method save_token
-
-Updates token value in configfile and saves as YAML if modified.
-
-If configfile is not defined, the token is printed to STDOUT for manual saving.
-
-=cut
-
-sub save_token {
- my $self = shift;
- if (!$self->configfile)
- {
- say "please save token: " . $self->token ;
- return 1;
- }
-
- my $config = $self->get_config_from_file( $self->configfile );
- if (!exists $config->{token} or $self->token ne $config->{token})
- {
- $config->{token} = $self->token;
- say "saving updated token!"; ## DEBUG
- use YAML::Any;
- YAML::Any::DumpFile( $self->configfile, $config);
- }
-}
+# requires provided by ::SimpleConfig
+with 'Facebook::Graph::role::save_token';
no Any::Moose;
__PACKAGE__->meta->make_immutable;
View
3 lib/Facebook/Graph/role/HTTPtoken.pm
@@ -92,9 +92,6 @@ sub _build_token
{
my $self = shift;
return $self->request_access_token( $self->code )->token;
-
- #my $resp = $self->request_access_token($self->code);
- #$resp->token;
}
sub verify_token
View
38 lib/Facebook/Graph/role/save_token.pm
@@ -0,0 +1,38 @@
+package Facebook::Graph::role::save_token;
+
+#ABSTRACT: Provides a save_token method to save token value to YAML config file.
+
+use v5.10;
+use Any::Moose 'Role';
+use YAML::Any;
+
+requires qw( get_config_from_file configfile token );
+# MooseX::SimpleConfig or MouseX::SimpleConfig will provide
+# both get_config_from_file and configfile
+
+=method save_token
+
+Updates token value in configfile and saves as YAML if modified.
+
+If configfile is not defined, the token is printed to STDOUT for manual saving.
+
+=cut
+
+sub save_token
+{
+ my $self = shift;
+ if ( !$self->configfile )
+ {
+ say "please save token: " . $self->token;
+ return 1;
+ }
+
+ my $config = $self->get_config_from_file( $self->configfile );
+ if ( !exists $config->{token} or $self->token ne $config->{token} )
+ {
+ $config->{token} = $self->token;
+ YAML::Any::DumpFile( $self->configfile, $config );
+ }
+}
+
+1;

0 comments on commit 8734594

Please sign in to comment.
Something went wrong with that request. Please try again.