1#!/usr/bin/env perl 2 3use strict; 4use warnings all => 'FATAL'; 5use Test::More skip_all => 6 "Mo isn't supported in a reasonable way since method modifiers are requires as well as adding private accessors."; 7use Test::Trap; 8use FindBin '$RealBin'; 9 10my @autosplit; 11 12BEGIN { 13 use Module::Runtime qw(use_module); 14 eval { use_module( "Mo", "0.36" ) } 15 or plan skip_all => "Need Mo (0.36) for this test"; 16 eval { use_module("Data::Record"); use_module("Regexp::Common"); } 17 and @autosplit = ( autosplit => ',' ); 18} 19 20{ 21 22 package tRole; 23 use Moo::Role; 24 use Mo 'default'; 25 use MooX::Options; 26 27 option 'bool' => ( is => 'ro' ); 28 option 'counter' => ( is => 'ro', repeatable => 1 ); 29 option 'empty' => ( is => 'ro', negatable => 1 ); 30 option 'verbose' => ( is => 'ro', negativable => 1 ); 31 option 'used' => ( is => 'ro' ); 32 option 'unused' => ( is => 'ro', short => 'no_used' ); 33 option 'split' => ( is => 'ro', format => 'i@', @autosplit ); 34 option 'has_default' => ( is => 'ro', default => sub {'foo'} ); 35 option 'range' => ( is => 'ro', format => 'i@', autorange => 1 ); 36 37 1; 38} 39{ 40 41 package t; 42 use Mo; 43 use Role::Tiny::With; 44 with 'tRole'; 45 46 1; 47} 48 49{ 50 51 package rRole; 52 use Moo::Role; 53 use Mo 'required'; 54 use MooX::Options; 55 56 option 'str_req' => ( is => 'ro', format => 's', required => 1 ); 57 58 1; 59} 60{ 61 62 package r; 63 use Mo; 64 use Role::Tiny::With; 65 with 'rRole'; 66 67 1; 68} 69 70{ 71 72 package sp_strRole; 73 use Moo::Role; 74 use Mo; 75 use MooX::Options; 76 77 option 'split_str' => ( is => 'ro', format => 's', @autosplit ); 78 option 'split_conflict_str1' => ( is => 'ro', format => 's', @autosplit ); 79 option 'split_conflict_str2' => ( is => 'ro', format => 's', @autosplit ); 80 81 1; 82} 83{ 84 85 package sp_str; 86 use Mo; 87 use Role::Tiny::With; 88 with 'sp_strRole'; 89 90 1; 91} 92 93{ 94 95 package sp_str_shortRole; 96 use Moo::Role; 97 use Mo; 98 use MooX::Options; 99 100 option 'split_str' => 101 ( is => 'ro', format => 's', @autosplit, short => 'z' ); 102 103 1; 104} 105{ 106 107 package sp_str_short; 108 use Mo; 109 use Role::Tiny::With; 110 with 'sp_str_shortRole'; 111 112 1; 113} 114 115{ 116 117 package dRole; 118 use Moo::Role; 119 use Mo 'coerce'; 120 use MooX::Options; 121 option 'should_die_ok' => 122 ( is => 'ro', coerce => sub { die "this will die ok" } ); 123 1; 124} 125{ 126 127 package d; 128 use Mo 'coerce'; 129 use Role::Tiny::With; 130 with 'dRole'; 131 1; 132} 133 134{ 135 136 package multi_reqRole; 137 use Moo::Role; 138 use Mo 'required'; 139 use MooX::Options; 140 option 'multi_1' => ( is => 'ro', required => 1 ); 141 option 'multi_2' => ( is => 'ro', required => 1 ); 142 option 'multi_3' => ( is => 'ro', required => 1 ); 143 1; 144} 145{ 146 147 package multi_req; 148 use Mo; 149 use Role::Tiny::With; 150 with 'multi_reqRole'; 151 1; 152} 153 154{ 155 156 package t_docRole; 157 use Moo::Role; 158 use Mo; 159 use MooX::Options; 160 option 't' => ( is => 'ro', doc => 'this is a test' ); 161 1; 162} 163{ 164 165 package t_doc; 166 use Mo; 167 use Role::Tiny::With; 168 with 't_docRole'; 169 1; 170} 171 172{ 173 174 package t_shortRole; 175 use Moo::Role; 176 use Mo; 177 use MooX::Options; 178 option 'verbose' => ( is => 'ro', short => 'v' ); 179 1; 180} 181 182{ 183 184 package t_short; 185 use Mo; 186 use Role::Tiny::With; 187 with 't_shortRole'; 188 1; 189} 190 191{ 192 193 package t_skipoptRole; 194 use Moo::Role; 195 use Mo; 196 use MooX::Options skip_options => [qw/multi/]; 197 198 option 'multi' => ( is => 'ro' ); 199 1; 200} 201{ 202 203 package t_skipopt; 204 use Mo; 205 use Role::Tiny::With; 206 with 't_skipoptRole'; 207 1; 208} 209 210{ 211 212 package t_prefer_cliRole; 213 use Moo::Role; 214 use Mo; 215 use MooX::Options prefer_commandline => 1; 216 217 option 't' => ( is => 'ro', format => 's' ); 218 1; 219} 220{ 221 222 package t_prefer_cli; 223 use Mo; 224 use Role::Tiny::With; 225 with 't_prefer_cliRole'; 226 1; 227} 228 229{ 230 231 package t_dashRole; 232 use Moo::Role; 233 use Mo; 234 use MooX::Options; 235 236 option 'start_date' => ( is => 'ro', format => 's', short => 's' ); 237 1; 238} 239{ 240 241 package t_dash; 242 use Mo; 243 use Role::Tiny::With; 244 with 't_dashRole'; 245 1; 246} 247 248{ 249 250 package t_jsonRole; 251 use Moo::Role; 252 use Mo; 253 use MooX::Options; 254 255 option 't' => ( is => 'ro', json => 1 ); 256 1; 257 258} 259 260{ 261 262 package t_json; 263 use Mo; 264 use Role::Tiny::With; 265 with 't_jsonRole'; 266 1; 267} 268 269{ 270 271 package t_jsonOptRole; 272 use Moo::Role; 273 use Mo; 274 use MooX::Options; 275 276 option 't' => ( is => 'ro', format => 'json' ); 277 1; 278 279} 280 281{ 282 283 package t_json_opt; 284 use Mo; 285 use Role::Tiny::With; 286 with 't_jsonOptRole'; 287 1; 288} 289 290{ 291 292 package rg_strRole; 293 use Moo::Role; 294 use Mo; 295 use MooX::Options; 296 297 option 'range_str' => ( 298 is => 'ro', 299 format => 's', 300 autorange => 1, 301 short => 'rs', 302 @autosplit 303 ); 304 option 'range_conflict_str1' => 305 ( is => 'ro', format => 's', autorange => 1 ); 306 option 'range_conflict_str2' => 307 ( is => 'ro', format => 's', autorange => 1 ); 308 309 1; 310} 311 312{ 313 314 package rg_str; 315 use Mo; 316 use Role::Tiny::With; 317 with 'rg_strRole'; 318 319 1; 320} 321 322{ 323 324 package rg_str_shortRole; 325 use Moo::Role; 326 use Mo; 327 use MooX::Options; 328 329 option 'range_str' => 330 ( is => 'ro', format => 's', autorange => 1, short => 'r' ); 331 332 1; 333} 334{ 335 336 package rg_str_short; 337 use Mo; 338 use Role::Tiny::With; 339 with 'rg_str_shortRole'; 340 341 1; 342} 343 344{ 345 346 package rg_str_short_commonRole; 347 use Moo::Role; 348 use Mo; 349 use MooX::Options; 350 351 option 'range_str' => 352 ( is => 'ro', format => 's', autorange => 1, short => 'r' ); 353 option 'range_json' => ( is => 'ro', format => 'json', short => 'j' ); 354 355 1; 356} 357 358{ 359 360 package rg_str_short_common; 361 use Role::Tiny::With; 362 use Mo; 363 364 with 'rg_str_short_commonRole'; 365 366 1; 367} 368 369subtest "Mo" => sub { 370 note "Test Mo"; 371 do $RealBin . '/base.st'; 372 $@ and diag $@; 373}; 374 375done_testing; 376